-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimgur_helper.user.js
More file actions
79 lines (72 loc) · 2.97 KB
/
imgur_helper.user.js
File metadata and controls
79 lines (72 loc) · 2.97 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// ==UserScript==
// @name imgur_helper
// @namespace someName
// @include http://imgur.com/*
// @include https://imgur.com/*
// @exclude http://imgur.com/ads*
// @exclude https://imgur.com/ads*
// @version 0.1
// @grant none
// ==/UserScript==
function init_imgur_helper(){
window.observer_callbacks = []; // contains [filter:func, exec:func, OPTIONAL tagNames:[]]
window._imgur_helper_loaded = false;
window.gallery_navigated_listener = [];
window.observer = new MutationObserver(function(mutations) {
for(var i=0; i < mutations.length; ++i){
var mutation = mutations[i];
for(var j=0; j < mutation.addedNodes.length; ++j){
var node = mutation.addedNodes[j];
if(node.nodeName == "#text") continue;
// galery navigation
if(node.className != undefined && node.className === "point-info-container left"){
for(var k=0; k < gallery_navigated_listener.length; gallery_navigated_listener[k](), ++k);
}
//console.log(node);
// all other handler
for(var k=0; k < observer_callbacks.length; ++k){ // oh my gosh is this aweful
if( observer_callbacks[k].tagNames != undefined && ( node.tagName === undefined || observer_callbacks[k].tagNames[node.tagName] === undefined) ){
//console.log("Skipped because of tagname ", node.tagName);
continue;
}
if( observer_callbacks[k].filter(node) ){
observer_callbacks[k].exec(node);
}
}
}
}
});
var target = document.querySelector('body');
observer.observe(target, { subtree: true, childList: true});
// init mod gui
if(window.location.pathname.indexOf('/account/settings') === 0){
var btn = $('<div class="textbox button" data-type="mods"><h2>Mods</h2><div class="active"></div><div>');
$('.right .panel').append(btn);
var space = $('<div class="nodisplay mod_settings" id="mod_settings"></div>');
$('.panel').filter('.left').append(space);
btn.click(function(){
btn.addClass("selected");
btn.parent().children().not('[data-type=mods]').removeClass('selected');
space.css('display', 'block');
space.parent().children().not('#mod_settings').css('display', 'none');
// we don't rewrite the url bar for now, as a reload would lead to a 404. (Could be fixed withhin this script though)
// history.pushState(null, "page 2", '/account/settings/mods');
});
btn.parent().children().not('[data-type=mods]').click(function(){
space.css('display', 'none');
});
}
window._imgur_helper_loaded = true;
}
function addJS_Node (text, s_URL) {
var scriptNode = document.createElement ('script');
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
var targ = document.getElementsByTagName('head')[0]
|| document.body || document.documentElement;
targ.appendChild (scriptNode);
}
console.log('Here is ' + window.location.href);
addJS_Node(init_imgur_helper.toString())
init_imgur_helper();