Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name 4chan Linkify
- // @namespace csimi
- // @author csimi
- // @description Linkification of text links.
- // @homepage http://userscripts.org/users/156405/scripts
- // @version 1.4.6
- // @updateURL http://userscripts.org/scripts/source/87750.meta.js
- // @icon http://i.imgur.com/JHVzK.png
- // @include http://boards.4chan.org/*
- // @include https://boards.4chan.org/*
- // ==/UserScript==
- (function () {
- ///////////////////////////////////
- var config = {
- 'multiLineLinks': true,
- 'targetBlank': false
- }
- ///////////////////////////////////
- function $ (a, b) { if (a && document.querySelector) return (b || document).querySelector(a); }
- function $$ (a, b) { if (a && document.querySelectorAll) return (b || document).querySelectorAll(a); }
- function foreach (a, f) { if (typeof(a) == 'object' && a.length && typeof(f) == 'function') { for (var i = 0; i < a.length; i++) { a[i] = f(a[i], i) || a[i]; } } }
- function ce (a, b) { if (typeof(a) != 'string') return; var c = document.createElement(a); foreach(b, function (d) { if (d.nodeType == 1) { c.appendChild(d); } else if (typeof(d) == 'object' && !d.length) { for (var k in d) { c.setAttribute(k, d[k]); } } else if (typeof(d) == 'string') { c.appendChild(document.createTextNode(d)); } }); return c; }
- function checkLinks (a) {
- if (!a) return;
- if (a.nodeType == 3) {
- var b = a.nodeValue.match(/[a-zA-Z][a-zA-Z0-9+-.]+:\/\/[^\s]+/);
- if (!b) b = a.nodeValue.match(/mailto:[^\s]+/);
- if (!b) b = a.nodeValue.match(/magnet:[^\s]+/);
- if (!b) b = a.nodeValue.match(/news:[^\s]+/);
- if (b && (a.parentNode.nodeName.toLowerCase() != 'a')) {
- var m = b[0];
- if (a.nodeValue.length == m.length) {
- var el = ce('a', [
- {'href': a.nodeValue,
- 'class': 'chanlinkify'},
- a.nodeValue
- ]);
- if (a.nextSibling && (((a.nextSibling.className && a.nextSibling.className === 'spoiler') || a.nextSibling.tagName && (a.nextSibling.tagName.toLowerCase() === "s" || a.nextSibling.tagName.toLowerCase() === "wbr") ) || a.nextSibling.nodeType === 3)) {
- a.nodeValue = a.nodeValue+((a.nextSibling.nodeType === 3)? a.nextSibling.nodeValue : ((a.nextSibling.childNodes.length)? a.nextSibling.childNodes[0].nodeValue : ''));
- a.parentNode.removeChild(a.nextSibling);
- return checkLinks(a);
- }
- if (config.targetBlank) el.setAttribute('target', 'blank');
- a.parentNode.replaceChild(el, a);
- }
- else {
- var c = a.nodeValue.indexOf(m);
- if (a.nodeValue.substring(c-1, c) == '(') {
- if (/(.*)\x29$/.test(m)) {
- m = m.match(/(.*)\x29$/)[1];
- c = a.nodeValue.indexOf(m);
- }
- }
- if (a.nodeValue.substring(c-2, c) == '("') {
- if (/(.*)\x22\x29$/.test(m)) {
- m = m.match(/(.*)\x22\x29$/)[1];
- c = a.nodeValue.indexOf(m);
- }
- }
- if (a.nodeValue.substring(c-2, c) == '(\'') {
- if (/(.*)\x27\x29$/.test(m)) {
- m = m.match(/(.*)\x27\x29$/)[1];
- c = a.nodeValue.indexOf(m);
- }
- }
- var d = c+m.length;
- if (c != 0) a.parentNode.insertBefore(document.createTextNode(a.nodeValue.substring(0, c)), a);
- var el = ce('a', [
- {'href': m,
- 'class': 'chanlinkify'},
- m
- ]);
- if (config.targetBlank) el.setAttribute('target', 'blank');
- a.parentNode.insertBefore(el, a);
- if (d == a.nodeValue.length) a.parentNode.removeChild(a);
- else {
- a.nodeValue = a.nodeValue.substring(d);
- checkLinks(a);
- }
- }
- }
- }
- else if (a.className == 'quote' || 'spoiler') checkLinks(a.childNodes[0]);
- }
- foreach($$('blockquote'), function (a) {
- foreach(a.childNodes, function (b) {
- checkLinks(b);
- });
- });
- foreach($$('span.subject'), function (b) {
- checkLinks(b.childNodes[0]);
- });
- function handler(e) {
- var t = e && e.target || e;
- if (t.nodeType === 1 && t.nodeName.toLowerCase() === 'div') {
- if (t.className.split(' ').filter(function (cls) { return cls === 'postContainer'; }).length) {
- foreach($('blockquote', t).childNodes, function (a) {
- checkLinks(a);
- });
- }
- }
- if (t.nodeType === 3 && t.parentNode.nodeName.toLowerCase() === 'blockquote') {
- checkLinks(t);
- }
- if (t.nodeName.toLowerCase() == 'blockquote') {
- foreach(t.childNodes, function (a) {
- checkLinks(a);
- });
- }
- }
- if (MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.OMutationObserver) {
- observer = new MutationObserver(function(a) {
- for (var i = 0; a[i]; i++) {
- foreach(a[i].addedNodes, handler);
- }
- });
- observer.observe($('.board'), {
- childList: true,
- subtree: true
- })
- } else {
- document.addEventListener('DOMNodeInserted', handler, false);
- }
- function appendNextTextNode (a, b) {
- var r = (a.parentNode.className == 'quote') ? a.parentNode : a;
- if (r.nextSibling && (r.nextSibling.nodeName.toLowerCase() == 'br')) {
- if (r.nextSibling.nextSibling && (r.nextSibling.nextSibling.nodeType == 3)) {
- var b = r.nextSibling.nextSibling;
- var c = b.nodeValue.match(/^[^\s]+/);
- if (!c) return;
- a.href += c[0];
- a.childNodes[0].nodeValue += c[0];
- if (b.nodeValue.length == c[0].length) {
- r.parentNode.removeChild(r.nextSibling);
- r.parentNode.removeChild(b);
- }
- else {
- r.parentNode.removeChild(r.nextSibling);
- b.nodeValue = b.nodeValue.substring(c[0].length);
- }
- }
- }
- else if (b === true && r.nextSibling && (r.nextSibling.nodeType == 3)) {
- var b = r.nextSibling;
- var c = b.nodeValue.match(/^[^\s]+/);
- if (!c) return;
- a.href += c[0];
- a.childNodes[0].nodeValue += c[0];
- if (b.nodeValue.length == c[0].length) {
- r.parentNode.removeChild(b);
- }
- else {
- b.nodeValue = b.nodeValue.substring(c[0].length);
- }
- }
- }
- if (config.multiLineLinks) document.addEventListener('click', function (e) {
- var t = e.target;
- if ((t.className == 'chanlinkify') && e.shiftKey && e.ctrlKey) {
- e.preventDefault();
- e.stopPropagation();
- appendNextTextNode(t);
- }
- }, false);
- })();
- // ==UserScript==
- // @id GPU embeds
- // @name gpu
- // @version 1.0
- // @namespace
- // @author
- // @description
- // @include http*
- // @run-at document-start
- // ==/UserScript==
- var d = document, s = function(a,b,c) { a.setAttribute(b,c); }, rm = function(a){ a.parentNode.removeChild(a); }, event = function(e) {
- if (e.animationName == 'nodeInserted') {
- if (e.target.tagName.match(/embed|object/i)) {
- try {
- var a1, a2, a3;
- for (var i=0,x=e.target.getElementsByTagName('param');i<x.length;i++) {
- if (x[i].name.match(/wmode/i)) {
- x[i].value = "direct";
- a1 = 1;
- } else
- if (x[i].name.match(/allowfullscreen/i)) {
- x[i].value = "true";
- a2 = 1;
- } else
- if (x[i].name.match(/allowscriptaccess/i)) {
- x[i].value = "always";
- a3 = 1;
- }
- }
- if (e.target.tagName.match(/object/i)) {
- var tmp = d.createElement('param');
- a1 || ((tmp.value='direct'),(tmp.name='wmode'),e.target.appendChild(tmp),(tmp=d.createElement('param')));
- a2 || ((tmp.value='true'),(tmp.name='allowFullScreen'),e.target.appendChild(tmp),(tmp=d.createElement('param')));
- a3 || ((tmp.value='always'),(tmp.name='allowScriptAccess'),e.target.appendChild(tmp));
- } else
- {
- (s(e.target, "allowfullscreen", "true"),s(e.target, "wmode", "direct"),s(e.target, "allowscriptaccess", "always"));
- }
- } catch(err) {
- console.log(err);
- }
- } else
- {
- rm(e.target);
- }
- }
- }, css = "@keyframes, nodeInserted { from { clip: rect(1px, auto, auto, auto); } to { clip: rect(0px, auto, auto, auto); } }\n\
- @-moz-keyframes nodeInserted { from { clip: rect(1px, auto, auto, auto); } to { clip: rect(0px, auto, auto, auto); } }\n\
- embed, object, script[id='bug.surrogate'], #ghostery-purple-bubble, div[id^=cometchat], script[src*=cometchat], link[href*=cometchat]/*, form#delform>div[style='float: right;']*/, body > script + center#topper + hr + center, body > script + center#topper + hr + center + hr + center#aaaa, body > div#thefuncapsule > table#yard, script[src='/js/advertisement.js'], div[id$='AdBar'], ul#WikiaNotifications, div[style='margin:3px auto; text-align:center'], br + div.adb, #WikiaRail > *:not(#WikiaSearch), #WikiaBarWrapper, div[id^=pim].postInfoM, div#overhead-you-know-what, td#sidebar-you-know-what, div.f.gruze-sidebar.left-sidebar.module-min.module-blocks.match-body-height, #fake-col-left, div.skiptranslate, div#rightCol[aria-label][role=complementary], a[target='_newtab'][href*='cect-shop.com'], body > div > script[type='text/javascript'] + div.body-navbar, div#pAdvertContainer + div#pContainer + div#toolbarContainer, div.WikiaBarCollapseWrapper, section#ExitstitialInfobox[class], script[src*=wikia], div#rightCol[role=complementary], ul.ShareRail, div.WikiaWideTablesWrapper > canvas[width] + img.popout, div.WikiaWideTablesWrapper > canvas[width], div.comment-ad, div.sleekadbubble, div.partial-ad, div#ad_footer_s, div#adv_overlay, div.ll + div.rr > div[style='margin-top:10px;'], div.ad-blocking-makes-fella-confused, div[gmi-name='ad_zone'], div.banner_728 { animation: nodeInserted .001s; -moz-animation: nodeInserted .001s; }";
- d.addEventListener('animationstart', event, false);
- function addStyle(a,b) {
- var newstyle = d.createElement("style");
- newstyle.setAttribute("type", "text/css");
- newstyle.appendChild(document.createTextNode(a));
- b.appendChild(newstyle);
- }
- (function applyCSS(){var h=d.getElementsByTagName("head");h&&h[0]?addStyle(css,h[0]):setTimeout(applyCSS,10)})();
Advertisement
Add Comment
Please, Sign In to add comment