-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
GeenStijl_Powned_Dumpert_Comment_Enhancer.user.js
156 lines (148 loc) · 5.52 KB
/
GeenStijl_Powned_Dumpert_Comment_Enhancer.user.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// ==UserScript==
// @name GeenStijl & Powned & Dumpert Comment Enhancer
// @namespace https://github.com/jerone/UserScripts
// @description Add features to enhance comments on GeenStijl & Powned & Dumpert & more.
// @author jerone
// @copyright 2014+, jerone (https://github.com/jerone)
// @license CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
// @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @homepage https://github.com/jerone/UserScripts/tree/master/GeenStijl_Powned_Dumpert_Comment_Enhancer
// @homepageURL https://github.com/jerone/UserScripts/tree/master/GeenStijl_Powned_Dumpert_Comment_Enhancer
// @downloadURL https://github.com/jerone/UserScripts/raw/master/GeenStijl_Powned_Dumpert_Comment_Enhancer/GeenStijl_Powned_Dumpert_Comment_Enhancer.user.js
// @updateURL https://github.com/jerone/UserScripts/raw/master/GeenStijl_Powned_Dumpert_Comment_Enhancer/GeenStijl_Powned_Dumpert_Comment_Enhancer.user.js
// @supportURL https://github.com/jerone/UserScripts/issues
// @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VCYMHWQ7ZMBKW
// @include http*://*geenstijl.nl/mt/archieven/*
// @include http*://*geenstijl.tv/*
// @include http*://*powned.tv/nieuws/*
// @include http*://*dumpert.nl/mediabase/*
// @include http*://*daskapital.nl/*
// @include http*://*glamora.ma/*
// @version 2.0
// @grant none
// ==/UserScript==
// cSpell:ignore Dumpert, dumpert, geenstijl, powned, daskapital, glamora, perma
/* eslint security/detect-object-injection: "off" */
(function () {
function proxy(fn) {
return function () {
var that = this;
return function (e) {
var args = that.slice(0); // clone;
args.unshift(e); // prepend event;
fn.apply(this, args);
};
}.call([].slice.call(arguments, 1));
}
function wait(condition, next) {
var loop = window.setInterval(function () {
if (condition() === true) {
window.clearInterval(loop);
next();
}
}, 100);
}
String.format = function (string) {
var args = Array.prototype.slice.call(arguments, 1, arguments.length);
return string.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] !== "undefined" ? args[number] : match;
});
};
var replyImgScr =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAABcSURBVChTjZBbDsAgCATl2PDFzW236RjqI+kmSsBxQS0i+q2GzKzVfBy8oOCj3L03bRIROjNHbQGBgRQx+TgC6ALQEawtGeNpzWNwETjD2xlVrGtp/et7ZpddfgEnfhsfVr//KQAAAABJRU5ErkJgggA=";
var permaImgScr =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAABGdBTUEAAK/INwWK6QAAAAlwSFlzAAAOwwAADsMBx2+oZAAAABZ0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMDvo9WkAAABfSURBVChTXY9BEsAgCAP7bMqpL4euDaJ2D0xMzKDXvWFmpSYjzsyIYP4YMQ2y7+rRrlhKh2ci091XDH1DJnPtlgsIetpYsTImmoxHVLuVMsHxaDf7D+tpQr/CAjnu/gJVo8cY6M1GEAAAAABJRU5ErkJggg==";
var commentsList = document.getElementById("comments");
if (commentsList) {
wait(
function () {
return (
commentsList.querySelectorAll("article .nsb,.comment .nsb")
.length > 0
);
},
function () {
Array.forEach(
commentsList.querySelectorAll("article,.comment"),
function (comment) {
var footer = comment.querySelector("footer,.footer");
if (comment.id) {
var perma = document.createElement("a");
perma.classList.add("nsb");
perma.setAttribute(
"href",
String.format("#{0}", comment.id),
);
perma.setAttribute(
"title",
String.format("Permalink #{0}", comment.id),
);
perma.style.backgroundImage = String.format(
"url('{0}')",
permaImgScr,
);
perma.style.backgroundPosition = "center center";
perma.style.marginRight = "4px";
if (
/https?:\/\/www\.powned\.tv\/nieuws\/.*/.test(
location.href,
)
) {
// add missing css;
perma.style.cursor = "pointer";
perma.style.cssFloat = "right";
perma.style.height = perma.style.width = "10px";
}
footer.appendChild(perma);
}
var textArea = document.getElementById("text");
if (textArea) {
var reply = document.createElement("span");
reply.classList.add("nsb");
reply.setAttribute("title", "Beantwoorden");
reply.style.backgroundImage = String.format(
"url('{0}')",
replyImgScr,
);
reply.style.backgroundPosition = "center center";
reply.style.marginRight = "4px";
if (
/https?:\/\/www\.powned\.tv\/nieuws\/.*/.test(
location.href,
)
) {
// add missing css;
reply.style.cursor = "pointer";
reply.style.cssFloat = "right";
reply.style.height = reply.style.width = "10px";
}
reply.addEventListener(
"click",
proxy(function () {
textArea.value += String.format(
"@{0}\n",
Array.map(
this.childNodes,
function (node) {
return node.nodeType === 3
? node.textContent.trim()
: "";
},
)
.join(" ")
.trim()
.replace(/\s{2,}/, " ")
.replace(/\s?\|\s?$/g, ""),
);
textArea.focus();
textArea.scrollIntoView();
}).bind(footer),
);
footer.appendChild(reply);
}
},
);
},
);
}
})();