Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name 2ch Deencoder
- // @namespace 2ch
- // @include https://2ch.hk/*
- // @version v0.2.1
- // @grant none
- // ==/UserScript==
- function r(el) {
- var a = el.getElementsByTagName('a');
- for (var i = 0; i < a.length; i++) {
- {
- let lc = a[i].href.slice(-1);
- if (/\.|\)|,/.test(lc)) {
- a[i].href = a[i].href.slice(0,-1);
- a[i].innerHTML = a[i].innerHTML.slice(0,-1);
- a[i].nextSibling.textContent = lc + a[i].nextSibling.textContent;
- }
- }
- var tmp = a[i].innerHTML;
- tmp = tmp.replace(/(?:#)([\w.]+)/, function (match) {
- return match.replace(/\.([0-9A-F]{2})/gi, '%$1');
- });
- try {
- tmp = decodeURI(tmp);
- }
- catch (e) {}
- tmp = tmp.replace(/https?:\/\/2ch\.hk\/(\w+)\/res\/(\w+)(\.html|\.(\w+))/, '2ch/$1:$2$4');
- tmp = tmp.replace(/https?:\/\/2ch\.hk\/faq\/faq_(\w+)\.html/, '2ch/faq:$1');
- tmp = tmp.replace(/https?:\/\/(4stor)\.ru\/[\w-]+\/\d+-([\w-]+)\.html/, '$1:$2');
- tmp = tmp.replace(/https?:\/\/(arhivach)\.org\/thread\//, '$1:');
- tmp = tmp.replace(/https?:\/\/(web\.archive)\.org\/web\/(\d+|\*)\/https?:\/\//, '$1:');
- tmp = tmp.replace(/https?:\/\/geektimes\.ru\/post\//, 'GT:');
- tmp = tmp.replace(/https?:\/\/github.com\//, 'git:');
- tmp = tmp.replace(/https?:\/\/([^.]+\.github\.io)\//, '$1:');
- tmp = tmp.replace(/https?:\/\/habrahabr\.ru\/company\/(\w+)\/blog\//, '$1.habr:');
- tmp = tmp.replace(/https?:\/\/habrahabr\.ru\/post\//, 'habr:');
- tmp = tmp.replace(/https?:\/\/(pastebin)\.com\/?([^/]{0,}\/|raw\.php\?i=)(\w+)/, '$1:$3');
- // tmp = tmp.replace(/https?:\/\/(pastebin\.com)\/?([^/]{0,}\/|raw\.php\?i=)(\w+)/, '$1:$3<br><iframe src="//$1/raw/$3" style="background:wheat;width:100%"></iframe>');
- tmp = tmp.replace(/https?:\/\/forum\.oszone\.net\/thread-(\d+)\.html/, 'forum.OSZone:$1');
- tmp = tmp.replace(/https?:\/\/(w+\.)?opennet\.ru\/opennews\/art\.shtml\?num=(\d+)/, 'news.opennet:$2');
- tmp = tmp.replace(/https?:\/\/(rghost)\.(ru|net)\//, '$1:');
- tmp = tmp.replace(/https?:\/\/sdi-tool\.org\S+/, 'SDI');
- tmp = tmp.replace(/https?:\/\/([^.]+)\.sourceforge\.net/, '$1.sf.net');
- tmp = tmp.replace(/https?:\/\/(sourceforge|sf)\.net\/p(rojects)?\/([^\/]+).?/, '$3.sf.net');
- // tmp = tmp.replace(/https?:\/\/(w+\.)?youtu(\.be\/|be\.com\/watch\?v=)([\d\w]+)/, 'youtube:$3');
- tmp = tmp.replace(/https?:\/\/(w+\.)?(youtube\.)com\/user\/([\d\w]+)\/?\S{0,}/, '$2user:$3');
- tmp = tmp.replace(/https?:\/\/vk\.com\/(\S+)/, 'vk:$1');
- tmp = tmp.replace(/https?:\/\/(vocaroo)\.com\/i\/(\S+)/, '$1:$2');
- tmp = tmp.replace(/http:\/\/((\w{2}\.)?([\w-]+\.wikia))\.com\/wiki\//, '$3:');
- tmp = tmp.replace(/https?:\/\/(\w+)(\.m)?\.wikipedia\.org\/wiki\//, '$1.wiki:');
- tmp = tmp.replace(/https?:\/\/(w+\.)?linux\.org\.ru\/(\w+)\/(\w+)\//, 'LOR.$2.$3:');
- tmp = tmp.replace(/https?:\/\/(play)\.(google)\.com\/store\/(apps)\/details\?id=\w+\.([\w.]+).*/, '$3@$2.$1:$4');
- tmp = tmp.replace(/https?:\/\/(f-droid)\.org\/packages\/\w+\.([\w.]+).*/, '$1:$2');
- //tmp = tmp.replace(//, '');
- /* Arch, Debian, Gentoo, LOR wikies
- https://wiki.debian.org/ath9k
- https://wiki.archlinux.org/index.php/Arch_Linux
- https://wiki.gentoo.org/wiki/GRUB2/ko
- https://lorwiki.org.ru/wiki/Что_такое_командная_строка_и_как_в_ней_работать
- */
- if ( tmp.search('wiki') + 1 ) {
- // tmp = tmp.replace(/https:\/\/(wiki\.)?([^.]+)\.\w{2,3}\/(wiki\/|index\.php(\/|\?title=)?|\w{2}\/)(.+)/, 'wiki.$2:$5');
- // tmp = tmp.replace(/https?:\/\/(www\.)?(wiki\.)?([^.]+)[^\/]+\/(wiki\/|index\.php(\/|\?title=)?|\w{2}\/)?(.+)/, 'wiki.$3:$6');
- tmp = tmp.replace(/https?:\/\/(www\.)?(wiki\.)?([^.]+)[^\/]+\/(wiki\/|index\.php(\/|\?title=)?|\w{2}\/)?(.+)/, 'wiki.$3:$6');
- }
- // fourm general
- tmp = tmp.replace(/https?:\/\/(w+\.|forums?\.)?([^.]+\.\w+)\/(forum\/)?(index\.php\?showtopic=|viewtopic\.php\?)(.*)/, 'forum.$2:$5');
- tmp = tmp.replace(/https?:\/\/chrome\.google\.com\/webstore\/detail\/([^/]+)\/\S+/, 'chrome_extension:$1');
- // Old style
- // tmp = tmp.replace(/https?:\/\/addons\.mozilla\.org(\/\w{2}(-\w{2})?)?\/?(firefox|android)?\/addon\/([^\/]+)/, 'firefox_addon:$4');
- tmp = tmp.replace(/https?:\/\/addons\.mozilla\.org(\/\w{2}(-\w{2})?)?\/?(firefox|android)?\/addon\/([^\/]+)(\/.+)?/, 'firefox_addon:$4');
- // After update
- tmp = tmp.replace(/https?:\/\/addons\.mozilla\.org\/downloads\/latest-?(\w+)?\/(\d+)\/addon-\d+-latest\.xpi[^\s]+/, 'firefox_addon:$2_$1');
- tmp = tmp.replace(/https?:\/\/addons\.opera\.com\/\w{2}-\w{2}\/extensions\/details\/([^/]+)/, 'opera_addon:$1');
- tmp = tmp.replace(/(https?:\/\/)www\./, '$1');
- tmp = tmp.replace(/\.html?$/, '');
- a[i].innerHTML = tmp.replace(/\/$/, '');
- }
- }
- r(document);
- [document.getElementById('posts-form'), document.querySelector('.thread')].forEach(node =>
- new MutationObserver(
- mutations => mutations.forEach( mutation => mutation.addedNodes.forEach( node=>r(node) ) )
- ).observe(node, { childList: true })
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement