Uncensored bitcoin url link fixer

make link-like things actually links.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Uncensored bitcoin url link fixer
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  make link-like things actually links.
// @author       It's not lupus. Go away.
// @match        https://www.reddit.com/r/noncensored_bitcoin/*
// @grant        none
// @require      https://cdnjs.cloudflare.com/ajax/libs/findAndReplaceDOMText/0.4.5/findAndReplaceDOMText.min.js
// ==/UserScript==

(function() {
    'use strict';

    var subs = [
        "bitcoin", "btc", "cryptocurrency", // currently active on subreddit
        "bitcoinmarkets", "buttcoin", "ethereum", // not active, but it ain't hurting nobody
        "ethtrader", "bitcoin_uncensored", "bitcoinall",
        "bitcoin_unlimited", "bitcoinbeginners", "bitcoincash",
        "coinbase", "bitcoinmining", "jobs4bitcoin", "openbazaar",
        "bitmarket", "blockstreams", "bitcoinxt", "mtgoxinsolvency",
        "bitcoinserious", "bitcoinnews", "kraken", "redditnotes" ]; // digging deep

    var findRegexp = new RegExp("(?:(?:[a-z]+\.)?reddit\.com)?\\/r\\/ ("+subs.join("|")+")\\S+", "gi");
    var replaceRegexp = new RegExp("r\\/ ("+subs.join("|")+")", "i");

    var fixLinks = _.debounce(function() {
        // regexps are fuzzy. this will probably work, until it doesn't. adjust as needed.
        // this is hardcoded to only work with "/r/ Bitcoin" links. revisit if it needs to match more.
        findAndReplaceDOMText(document.body, {
            find: findRegexp,
            replace: function(portion, matches) {
                var link = matches[0].replace(/^(?:[a-z]+\.)?reddit\.com/i,'').replace(replaceRegexp, 'r\/$1');
                return $("<A>").attr("href", link).text(link)[0];
            }
        });
        // let's make reddit usernames into links too.
        findAndReplaceDOMText(document.body, {
            find: /((?:post|comment) by )(\S+)/gi,
            replace: function (portion, matches) {
                if (portion.text != matches[0]) { // only replace full matches, or we'll end up replacing ourselves.
                    return portion.node.cloneNode();
                }
                var before = matches[1];
                var username = matches[2];
                return $("<span>").text(before).append($("<A>").attr("href", "/u/"+username).text(username))[0];
            }
        });
    }, 250);

    (new MutationObserver(fixLinks)).observe(document.body, {
        childList: true,
        subTree: true
    });
    fixLinks();
})();