forked from jesus2099/konami-command
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfreenode_WEBCHAT-CONNECT.user.js
More file actions
64 lines (64 loc) · 3.36 KB
/
freenode_WEBCHAT-CONNECT.user.js
File metadata and controls
64 lines (64 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// ==UserScript==
// @name freenode. WEBCHAT CONNECT
// @version 2016.6.15
// @changelog https://github.com/jesus2099/konami-command/commits/master/freenode_WEBCHAT-CONNECT.user.js
// @description webchat.freenode.net: Remembers your last used nickname and channels. Reloads properly if problem. cleverly focus first empty field.
// @supportURL https://github.com/jesus2099/konami-command/labels/freenode_WEBCHAT-CONNECT
// @compatible opera(12.18.1872)+violentmonkey my own setup
// @compatible firefox(39)+greasemonkey tested sometimes
// @compatible chromium(46)+tampermonkey tested sometimes
// @compatible chrome+tampermonkey should be same as chromium
// @namespace https://github.com/jesus2099/konami-command
// @downloadURL https://github.com/jesus2099/konami-command/raw/master/freenode_WEBCHAT-CONNECT.user.js
// @updateURL https://github.com/jesus2099/konami-command/raw/master/freenode_WEBCHAT-CONNECT.user.js
// @author PATATE12
// @licence CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
// @since 2011
// @icon data:image/gif;base64,R0lGODlhEAAQAKEDAP+/3/9/vwAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/glqZXN1czIwOTkAIfkEAQACAwAsAAAAABAAEAAAAkCcL5nHlgFiWE3AiMFkNnvBed42CCJgmlsnplhyonIEZ8ElQY8U66X+oZF2ogkIYcFpKI6b4uls3pyKqfGJzRYAACH5BAEIAAMALAgABQAFAAMAAAIFhI8ioAUAIfkEAQgAAwAsCAAGAAUAAgAAAgSEDHgFADs=
// @grant none
// @match *://webchat.freenode.net/
// @run-at document-end
// ==/UserScript==
setTimeout(function() {
"use strict";
var userjs = {name: "freenode. WEBCHAT CONNECT", key: "j2fwc"};
var channels = "#github,#last.fm,##musicbrainz-lol,#musicbrainz";
var inputs = document.getElementsByTagName("input");
document.head.appendChild(document.createElement("style")).setAttribute("type", "text/css");
var css = document.styleSheets[document.styleSheets.length - 1];
css.insertRule(".qwebirc-qui.topic { font-size: .8em; }", 0);
if (document.body.textContent.trim().match(/^412 - Precondition Failed$/) || !document.body.textContent.match(/connect.+nickname.+channels/i)) {
self.location.reload();
} else if (document.getElementsByTagName("frameset").length == 0 && inputs && inputs[0] && inputs[1]) {
self.addEventListener("focus", cleverFocus);
storify(inputs[0], "nickname");
storify(inputs[1], "channels");
cleverFocus();
inputs[1].style.setProperty("width", "100%");
inputs[1].setAttribute("placeholder", channels);
inputs[1].parentNode.style.setProperty("border-bottom", "1px dashed black");
inputs[1].parentNode.parentNode.setAttribute("title", "example: « " + channels + " »");
}
function cleverFocus(event) {
if (document.querySelector("table.qwebirc-loginbox")) {
for (var i = 0; i < 2; i++) {
if (inputs[i].value.trim().length == 0) {
inputs[i].focus();
return inputs[i];
}
}
}
}
function storify(field, key) {
var _key = userjs.key + "_" + key;
field.setAttribute("ref", _key);
field.value = localStorage.getItem(_key);
field.addEventListener("change", function(event) {
var key = this.getAttribute("ref");
if (key && key.match(new RegExp("^" + userjs.key + "_\\w+"))) {
if (key.match(/channels/)) { this.value = this.value.replace(/[\s:;,]+/g, ",").replace(/^,|,$/g, ""); }
localStorage.setItem(key, this.value);
}
});
}
}, 1000);