Blur Title Reddit

Blurring a title which marked as spoiler in reddit, just like in fallout subreddit.

目前為 2017-02-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name        Blur Title Reddit
// @namespace   https://gf.qytechs.cn/users/102866
// @description Blurring a title which marked as spoiler in reddit, just like in fallout subreddit.
// @include     https://*.reddit.com/*
// @include     http://*.reddit.com/*
// @exclude     https://*.reddit.com/r/fallout/*
// @exclude     http://*.reddit.com/r/fallout/*
// @exclude     https://*.reddit.com/r/*/comments/*
// @exclude     http://*.reddit.com/r/*/comments/*
// @require     https://code.jquery.com/jquery-3.1.1.min.js
// @author      TieL
// @version     0.0.08
// @grant       GM_addStyle
// ==/UserScript==

// Append some text to the element with id someText using the jQuery library. TEST JQUERY
//$("#hsts_pixel").append(" more text.");

//Add css
//console.log("Begin");
GM_addStyle ( "                           \
bdi.btr_title                             \
{                                         \
    color:rgba(255,60,231,0) !important;  \
    text-shadow: 0px 0px 1em black;       \
    padding: 0 2px;                       \
}                                         \
");

//GM_addStyle("                             \
//bdi.btr_title:hover,bdi.btr_title:focus   \
//{                                         \
//    color:black!important;                \
//    background:transparent!important;     \
//    text-decoration:none!important;       \
//    text-shadow:0 0.1px 0 #dcddce         \
//}                                         \
//");

GM_addStyle ( "                           \
bdi.btr_trans                             \
{                                         \
    transition: all 0.5s ease;            \
}                                         \
");

GM_addStyle ( "                           \
.title                                    \
{                                         \
    overflow: visible !important;         \
}                                         \
" );
//end of css
//console.log("its working styles");

var titles = document.querySelectorAll("a.title");
var titlesDiv = document.querySelectorAll("div.spoiler");
var titlesTitle = [];
//var color = document.querySelectorAll("a.title").style.color;
var stringArr = [];
var stringOri = [];
var string;
var stringStartbdi = '<bdi class = "btr_main btr_title btr_trans">';
var stringEndbdi = '</bdi>';
var stringCSS;
var len = [];
var i;
var firstB;
var lastB;
var col;
var lengthOfIndexes;
var arrBeg = [];
var arrEnd = [];

Main();

function Main() {
    console.log(titlesDiv);
    myFunction();
}

function myFunction() {
    for (i = 0; i < titlesDiv.length; i++) {
        if (titlesDiv[i].querySelector("div.entry.unvoted")) {
            titlesTitle[i] = titlesDiv[i].querySelector("div.entry.unvoted").querySelector("p.title").querySelector("a.title");
        } else
        {
            titlesTitle[i] = titlesDiv[i].querySelector("div.entry").querySelector("p.title").querySelector("a.title");
        }
    }

    for (i = 0; i < titlesDiv.length; i++) {
        len[i] = titlesTitle[i].innerHTML.length;
        console.log(titlesTitle[i].innerHTML, len[i]);
        stringArr[i] = titlesTitle[i].innerHTML;
        if (col == null) {
            $(function () {
                col = $(titlesTitle[0]).css("color");
                console.log("origin color :", col);
                stringCSS = "                             \
            bdi.btr_title:hover,bdi.btr_title:focus     \
            {                                         \
                color:" + col + "!important;          \
                background:transparent!important;     \
                text-decoration:none!important;       \
                text-shadow:0 0.1px 0 #dcddce         \
            }                                         \
            ";
                //console.log(stringCSS);
                GM_addStyle(stringCSS);
            });
        }
        findBrac(len[i], stringArr[i], titlesTitle[i]);
    }
}

function findBrac(l, sArr, tTitle) {
   // console.log(getAllIndexes(sArr, "[", "("));
    lengthOfIndexes = getAllIndexes(sArr, "[", "(").length;
    switch(lengthOfIndexes) {
        case 0:
            changeString(l, sArr, tTitle, 0);
            break;
        case 1:
            changeString(l, sArr, tTitle, 1);
            break;
        case 2:
            changeString(l, sArr, tTitle, 2);
            break;
        case 3:
            changeString(l, sArr, tTitle, 1); //TODO 3
            break;
        case 4:
            changeString(l, sArr, tTitle, 1); //TODO 4
            break;
        case 5:
            changeString(l, sArr, tTitle, 1); //TODO MAYBE 5
            break;
        default:
            changeString(l, sArr, tTitle, 0);
            return;
    } 
}

function changeString(l, sArr, tTitle, amount) {
    arrBeg = getAllIndexes(sArr, "[", "(");
    arrEnd = getAllIndexes(sArr, "]", ")");
    console.log("*str of brackets :", arrBeg);
    console.log("*end of brackets :", arrEnd);
    if (amount === 0) {
        string = stringStartbdi + ' ' + sArr + ' ' + stringEndbdi;
        console.info(string);
        tTitle.innerHTML = string;
        return;
    }
    if (amount === 1) {
        console.log("*words in brackets :", sArr.substring(arrBeg[0], arrEnd[0] + 1));
        if (arrBeg[0] <= 2)
        {
            string = sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, l) + ' ' + stringEndbdi;
            console.info(string);
            tTitle.innerHTML = string;
            return;
        } else if (arrEnd[0] >= l - 2) {
            string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], l);
            console.info(string);
            tTitle.innerHTML = string;
            return;
        } else
        {
            string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, l) + ' ' + stringEndbdi;
            console.info(string);
            tTitle.innerHTML = string;
            return;
        }
    }

    if (amount === 2) {
        var a;
        var s = '';
        for (a = 0; a < arrBeg.length; a++) {
            s += sArr.substring(arrBeg[a], arrEnd[a] + 1) + ' ';
        }
        console.log("*words in brackets :", s);
        if (arrBeg[0] <= 2) {
            if (arrEnd[0] + 4 > arrBeg[1])
            {
                string = sArr.substring(arrBeg[0], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, l) + ' ' + stringEndbdi;
                console.info(string);
                tTitle.innerHTML = string;
                return;
            } else if (arrEnd[1] >= l - 2) {
                string = sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], l);
                console.info(string);
                tTitle.innerHTML = string;
                return;
            } else
            {
                string = sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, l) + ' ' + stringEndbdi;
                console.info(string);
                tTitle.innerHTML = string;
                return;
            }
        } else if (arrEnd[1] >= l - 2) {
            if (arrBeg[1] - 4 < arrEnd[0]) {
                string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], l);
                console.info(string);
                tTitle.innerHTML = string;
                return;
            } else if (arrBeg[0] <= 2) {
                string = sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], l);
                console.info(string);
                tTitle.innerHTML = string;
                return;
            } else {
                string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], l);
                console.info(string);
                tTitle.innerHTML = string;
                return;
            }
        } else
        {
            if (arrEnd[0] + 3 >= arrBeg[1]) {
                string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, l) + ' ' + stringEndbdi;
                console.info(string);
                tTitle.innerHTML = string;
                return;
            } else {
                string = stringStartbdi + ' ' + sArr.substring(0, arrBeg[0]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[0], arrEnd[0] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[0] + 1, arrBeg[1]) + ' ' + stringEndbdi + ' ' + sArr.substring(arrBeg[1], arrEnd[1] + 1) + ' ' + stringStartbdi + ' ' + sArr.substring(arrEnd[1] + 1, l) + ' ' + stringEndbdi;
                console.info(string);
                tTitle.innerHTML = string;
                return;
            }
        }
    }
}

function getAllIndexes(arr, val1, val2) {
    var indexes = [], x;
    for (x = 0; x < arr.length; x++)
        if (arr[x] === val1 || arr[x] === val2)
            indexes.push(x);
    return indexes;
}


// ------------
//  TODO
// ------------

/* TODO STARTS
    1)Rewrite everything in Jquery ***RESEARCH NEEDED***
    2)Made it exclude of users, mean that post of their users WILL NOT bluring
    3)Make it exclude of linkflairs, because every subreddit has its own flair its hard ***RESEARCH NEEDED***
     3.1)Some subreddits has own spoiler-flair, which can be good to blur, because they don't use 
    buildin in reddit
    4)Support RES ***RESEARCH NEEDED***
     4.1)Or similar infinite reddit ***RESEARCH NEEDED***
    5)Support Chrome ***RESEARCH NEEDED***
    6)Make it different colors(if used, like in r/anime rewatch is blue and discussion are red) in css
    trough css [href=] or id # 
✓    7)Make it proporly edentity everything in brackets   //DONE 0.0.07                                                                           
     7.1)Make it blur title which have more then 3 groups of brackets
     7.2)Exclude some brackets which have text like 2011, jan 2007, etc. probably specific 
    subreddit only
    8)What it make that if you clicked on post which are blurry WILL NOT going to blurry 
    again ***RESEARCH NEEDED***
     8.1)What it remember color after you clicked ***RESEARCH NEEDED***
    9)Make it if brackets in the middle should unblury two or more part, dont know how 
    currently ***RESEARCH NEEDED***
    10)Want it if title whithout brackets but has name of anime, show etc. blur everything exclude NAME, its hard
    11)Add if title(Somehow)... full title in brackets, forced blur anyway 
    12)Make it work when searching
    13)Make options ***RESEARCH NEEDED***
TODO ENDS */

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址