[feat] Detects multiple instances. Re-detects every second. Warning moved.
This allows the user to enjoy "infinite scroll" without worrying about future script injections. It moves the warning to next-to the "reblog" button, so you get a clearer picture of what you're up against. It also no longer interferes with the reblog iframe, so you still get full interactivity.
This commit is contained in:
parent
faac34ba93
commit
7b532fd83c
|
@ -3,19 +3,52 @@
|
||||||
// @namespace http://elfsternberg.com
|
// @namespace http://elfsternberg.com
|
||||||
// @version 0.1
|
// @version 0.1
|
||||||
// @description Detect if a Tumblr post has an embedded script in it
|
// @description Detect if a Tumblr post has an embedded script in it
|
||||||
// @author Elf M. Sternberg <elf.sternberg@gmail.com>
|
// @author You
|
||||||
// @match http://*.tumblr.com/post/*
|
// @match http://*.tumblr.com/post/*
|
||||||
// @grant none
|
// @grant none
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
/* jshint -W097 */
|
/* jshint -W097 */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function tumblr_reblog_warning() {
|
if (!Element.prototype.matches) Element.prototype.matches = Element.prototype.msMatchesSelector;
|
||||||
var post = document.querySelectorAll('.post-wrapper script');
|
if (!Element.prototype.closest) Element.prototype.closest = function(selector) {
|
||||||
if (post.length > 0) {
|
var el = this;
|
||||||
document.body.innerHTML += ('<div style="background-color: rgba(0,0,0,0.6); float: right; position: absolute; top: 60px; width: 320px; color:limegreen; border: 4px solid limegreen; z-index: 50">' +
|
while (el) {
|
||||||
'SCRIPT DETECTED</div>');
|
if (el.matches(selector)) {
|
||||||
|
return el;
|
||||||
}
|
}
|
||||||
|
el = el.parentElement;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function createFrag(htmlStr) {
|
||||||
|
var frag = document.createDocumentFragment(),
|
||||||
|
temp = document.createElement('div');
|
||||||
|
temp.innerHTML = htmlStr;
|
||||||
|
while (temp.firstChild) {
|
||||||
|
frag.appendChild(temp.firstChild);
|
||||||
|
}
|
||||||
|
return frag;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.setTimeout(tumblr_reblog_warning, 500);
|
function tumblr_reblog_warning() {
|
||||||
|
var post = document.querySelectorAll('.post-wrapper script');
|
||||||
|
var parent;
|
||||||
|
var already;
|
||||||
|
var panel;
|
||||||
|
for(var i = 0; i < post.length; i++) {
|
||||||
|
parent = post[i].closest('.post-wrapper');
|
||||||
|
already = parent.querySelectorAll('.script-detected');
|
||||||
|
if (already.length == 0) {
|
||||||
|
parent.style.border = "4px solid cyan";
|
||||||
|
panel = parent.querySelector('.post-footer')
|
||||||
|
panel.insertBefore(
|
||||||
|
createFrag('<div class="script-detected" style="background-color: rgba(0,0,0,0.6); float: left; color:limegreen; border: 4px solid limegreen; z-index: 50">' +
|
||||||
|
'SCRIPT DETECTED</div>'),
|
||||||
|
panel.childNodes[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setTimeout(tumblr_reblog_warning, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(tumblr_reblog_warning, 500);
|
||||||
|
|
Loading…
Reference in New Issue