Advertisement
AHOHNMYC

2ch Deencoder

Oct 9th, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        2ch Deencoder
  3. // @namespace   2ch
  4. // @include     https://2ch.hk/*
  5. // @version     v0.2.1
  6. // @grant       none
  7. // ==/UserScript==
  8.  
  9. function r(el) {
  10.     var a = el.getElementsByTagName('a');
  11.     for (var i = 0; i < a.length; i++) {
  12.  
  13.         {
  14.             let lc = a[i].href.slice(-1);
  15.             if (/\.|\)|,/.test(lc)) {
  16.                 a[i].href = a[i].href.slice(0,-1);
  17.                 a[i].innerHTML = a[i].innerHTML.slice(0,-1);
  18.                 a[i].nextSibling.textContent = lc + a[i].nextSibling.textContent;
  19.             }
  20.         }
  21.  
  22.         var tmp = a[i].innerHTML;
  23.         tmp = tmp.replace(/(?:#)([\w.]+)/, function (match) {
  24.             return match.replace(/\.([0-9A-F]{2})/gi, '%$1');
  25.         });
  26.         try {
  27.             tmp = decodeURI(tmp);
  28.         }
  29.         catch (e) {}
  30.         tmp = tmp.replace(/https?:\/\/2ch\.hk\/(\w+)\/res\/(\w+)(\.html|\.(\w+))/, '2ch/$1:$2$4');
  31.         tmp = tmp.replace(/https?:\/\/2ch\.hk\/faq\/faq_(\w+)\.html/, '2ch/faq:$1');
  32.         tmp = tmp.replace(/https?:\/\/(4stor)\.ru\/[\w-]+\/\d+-([\w-]+)\.html/, '$1:$2');
  33.         tmp = tmp.replace(/https?:\/\/(arhivach)\.org\/thread\//, '$1:');
  34.         tmp = tmp.replace(/https?:\/\/(web\.archive)\.org\/web\/(\d+|\*)\/https?:\/\//, '$1:');
  35.         tmp = tmp.replace(/https?:\/\/geektimes\.ru\/post\//, 'GT:');
  36.         tmp = tmp.replace(/https?:\/\/github.com\//, 'git:');
  37.         tmp = tmp.replace(/https?:\/\/([^.]+\.github\.io)\//, '$1:');
  38.         tmp = tmp.replace(/https?:\/\/habrahabr\.ru\/company\/(\w+)\/blog\//, '$1.habr:');
  39.         tmp = tmp.replace(/https?:\/\/habrahabr\.ru\/post\//, 'habr:');
  40.         tmp = tmp.replace(/https?:\/\/(pastebin)\.com\/?([^/]{0,}\/|raw\.php\?i=)(\w+)/, '$1:$3');
  41.         //    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>');
  42.         tmp = tmp.replace(/https?:\/\/forum\.oszone\.net\/thread-(\d+)\.html/, 'forum.OSZone:$1');
  43.         tmp = tmp.replace(/https?:\/\/(w+\.)?opennet\.ru\/opennews\/art\.shtml\?num=(\d+)/, 'news.opennet:$2');
  44.         tmp = tmp.replace(/https?:\/\/(rghost)\.(ru|net)\//, '$1:');
  45.         tmp = tmp.replace(/https?:\/\/sdi-tool\.org\S+/, 'SDI');
  46.         tmp = tmp.replace(/https?:\/\/([^.]+)\.sourceforge\.net/, '$1.sf.net');
  47.         tmp = tmp.replace(/https?:\/\/(sourceforge|sf)\.net\/p(rojects)?\/([^\/]+).?/, '$3.sf.net');
  48.         //    tmp = tmp.replace(/https?:\/\/(w+\.)?youtu(\.be\/|be\.com\/watch\?v=)([\d\w]+)/, 'youtube:$3');
  49.         tmp = tmp.replace(/https?:\/\/(w+\.)?(youtube\.)com\/user\/([\d\w]+)\/?\S{0,}/, '$2user:$3');
  50.         tmp = tmp.replace(/https?:\/\/vk\.com\/(\S+)/, 'vk:$1');
  51.         tmp = tmp.replace(/https?:\/\/(vocaroo)\.com\/i\/(\S+)/, '$1:$2');
  52.         tmp = tmp.replace(/http:\/\/((\w{2}\.)?([\w-]+\.wikia))\.com\/wiki\//, '$3:');
  53.         tmp = tmp.replace(/https?:\/\/(\w+)(\.m)?\.wikipedia\.org\/wiki\//, '$1.wiki:');
  54.         tmp = tmp.replace(/https?:\/\/(w+\.)?linux\.org\.ru\/(\w+)\/(\w+)\//, 'LOR.$2.$3:');
  55.         tmp = tmp.replace(/https?:\/\/(play)\.(google)\.com\/store\/(apps)\/details\?id=\w+\.([\w.]+).*/, '$3@$2.$1:$4');
  56.         tmp = tmp.replace(/https?:\/\/(f-droid)\.org\/packages\/\w+\.([\w.]+).*/, '$1:$2');
  57.         //tmp = tmp.replace(//, '');
  58.  
  59.         /* Arch, Debian, Gentoo, LOR wikies
  60. https://wiki.debian.org/ath9k
  61. https://wiki.archlinux.org/index.php/Arch_Linux
  62. https://wiki.gentoo.org/wiki/GRUB2/ko
  63. https://lorwiki.org.ru/wiki/Что_такое_командная_строка_и_как_в_ней_работать
  64. */
  65.         if ( tmp.search('wiki') + 1 ) {
  66. //            tmp = tmp.replace(/https:\/\/(wiki\.)?([^.]+)\.\w{2,3}\/(wiki\/|index\.php(\/|\?title=)?|\w{2}\/)(.+)/, 'wiki.$2:$5');
  67. //            tmp = tmp.replace(/https?:\/\/(www\.)?(wiki\.)?([^.]+)[^\/]+\/(wiki\/|index\.php(\/|\?title=)?|\w{2}\/)?(.+)/, 'wiki.$3:$6');
  68.             tmp = tmp.replace(/https?:\/\/(www\.)?(wiki\.)?([^.]+)[^\/]+\/(wiki\/|index\.php(\/|\?title=)?|\w{2}\/)?(.+)/, 'wiki.$3:$6');
  69.  
  70.         }
  71.  
  72.         // fourm general
  73.         tmp = tmp.replace(/https?:\/\/(w+\.|forums?\.)?([^.]+\.\w+)\/(forum\/)?(index\.php\?showtopic=|viewtopic\.php\?)(.*)/, 'forum.$2:$5');
  74.  
  75.  
  76.         tmp = tmp.replace(/https?:\/\/chrome\.google\.com\/webstore\/detail\/([^/]+)\/\S+/, 'chrome_extension:$1');
  77.         // Old style
  78. //        tmp = tmp.replace(/https?:\/\/addons\.mozilla\.org(\/\w{2}(-\w{2})?)?\/?(firefox|android)?\/addon\/([^\/]+)/, 'firefox_addon:$4');
  79.         tmp = tmp.replace(/https?:\/\/addons\.mozilla\.org(\/\w{2}(-\w{2})?)?\/?(firefox|android)?\/addon\/([^\/]+)(\/.+)?/, 'firefox_addon:$4');
  80.         // After update
  81.         tmp = tmp.replace(/https?:\/\/addons\.mozilla\.org\/downloads\/latest-?(\w+)?\/(\d+)\/addon-\d+-latest\.xpi[^\s]+/, 'firefox_addon:$2_$1');
  82.         tmp = tmp.replace(/https?:\/\/addons\.opera\.com\/\w{2}-\w{2}\/extensions\/details\/([^/]+)/, 'opera_addon:$1');
  83.  
  84.         tmp = tmp.replace(/(https?:\/\/)www\./, '$1');
  85.         tmp = tmp.replace(/\.html?$/, '');
  86.         a[i].innerHTML = tmp.replace(/\/$/, '');
  87.     }
  88. }
  89.  
  90. r(document);
  91.  
  92. [document.getElementById('posts-form'), document.querySelector('.thread')].forEach(node =>
  93.     new MutationObserver(
  94.         mutations => mutations.forEach( mutation => mutation.addedNodes.forEach( node=>r(node) ) )
  95.     ).observe(node, { childList: true })
  96. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement