Unsurly

Rewrites sur.ly links back to their original form

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Unsurly
// @namespace   binoc.software.projects.userscript.unsurly
// @description Rewrites sur.ly links back to their original form
// @include     http://forum.palemoon.org/*
// @include     https://forum.palemoon.org/*
// @version     1.0b1
// @grant       none
// ==/UserScript==

// Polyfill ES6 string.prototype.includes
if (!String.prototype.includes) {
  String.prototype.includes = function(search, start) {
    'use strict';
    if (typeof start !== 'number') {
      start = 0;
    }
    
    if (start + search.length > this.length) {
      return false;
    } else {
      return this.indexOf(search, start) !== -1;
    }
  };
}

// Actual Script
function funcRewriteSurly() {
    var links, thisLink;
    links = document.evaluate("//a[@href]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

    for (var i=0;i<links.snapshotLength;i++) {
        var thisLink = links.snapshotItem(i);
        
        if (thisLink.href.includes('outbound.palemoon.org')) {
            thisLink.href = thisLink.href.replace('outbound.palemoon.org/', '');
            thisLink.href = unescape(thisLink.href);
        }
        else if (thisLink.href.includes('sur.ly')) {
            thisLink.href = thisLink.href.replace('sur.ly/o/', '');
            thisLink.href = thisLink.href.replace('/AA010667', '');
            thisLink.href = unescape(thisLink.href);
        }
    }
}

window.onload = funcRewriteSurly;