老司机传说

支持琉璃神社、灵梦御所等,全自动。自动展开神社隐藏的链接、自动开启御所老司机模式、自动转换神社神秘代码、自动填写御所打开的百度网盘提取码。飙车,现在只需要点开文章和点击链接。

As of 2016-09-10. See the latest version.

// ==UserScript==
// @name         老司机传说
// @namespace    http://www.ocrosoft.com/?p=1005
// @version      0.732
// @description  支持琉璃神社、灵梦御所等,全自动。自动展开神社隐藏的链接、自动开启御所老司机模式、自动转换神社神秘代码、自动填写御所打开的百度网盘提取码。飙车,现在只需要点开文章和点击链接。
// @author       ocrosoft
// @match        https://blog.reimu.net/*
// @match        *://pan.baidu.com/share/init?*
// @match        *://yun.baidu.com/share/init?*
// @match        *://www.hacg.li/*
// @match        *://www.hacg.lol/*
// @match        *://www.hacg.red/*
// @match        *://sexacg.com/*
// @icon         http://www.ocrosoft.com/lsj.png
// @require      http://code.jquery.com/jquery-2.1.4.min.js
// @grant        unsafeWindow
// ==/UserScript==
//开关Begin//1表示打开,0表示关闭
//Ctrl+Enter开启老司机模式:
var odON=1;
//前进后退支持:
var bfON=1;
//自动填写百度提取码:
var aiON=1;
//御所重口味内容不自动开启老司机模式:
var auodOFF=1;
//开关End//
var urls=location.href;
var hash=location.hash;
var host=location.hostname.replace(/^www\./i,'').toLowerCase();
var site = {
    'baidu.com': {
        chk:  /^[a-z0-9]{4}$/,
        code: '#accessCode',
        btn:  '#submitBtn'
    },
    'weiyun.com': {
        chk: /^[a-z0-9]{4}$/i,
        code: '#outlink_pwd',
        btn:  '#outlink_pwd_ok'
    },
    'codeRule':/(?:提取|访问|密|艾)[码碼]?\s*[:: ]?\s*([a-z\d]{4})/i,
    'JumpUrl':{
        'zhihu.com' :  $('A[href^="http://link.zhihu.com/?target="]'),
        //'tieba.baidu.com' : $('A[href^="http://jump.bdimg.com/safecheck/index?url="]')
    }
};
unsafeWindow.eve = Event;
//判断是否自动开启老司机模式
function ifshow(){
    if(auodOFF===0)return 1;//跳过重口味判断
    var ifShow=1;
    var tags=document.getElementsByClassName('tags-links')[0];
    for(var cd=0;cd<tags.childNodes.length;cd++){
        var tga=tags.childNodes[cd];
        if(tga&&tga.innerText){
            if(tga.innerText.indexOf("重口")!=-1){
                ifShow=0;
                if(!document.getElementsByTagName('pre')[0])return 0;
                var dv = document.createElement("div");
                dv.innerHTML = '此页含重口味内容,未开启老司机模式。请使用Ctrl+Enter开启。';
                dv.style.background="#fff";dv.style.position="fixed";dv.style.heght=50;
                dv.style.zIndex=99999;dv.style.textAlign="center";dv.id="attention";
                var page = document.getElementsByClassName("site-content")[0];
                page.insertBefore(dv,page.firstChild);
                document.getElementById("attention").style.width=page.offsetWidth+"px";
                return 0;
            }
        }
    }
    $("#attention").remove();
    return 1;
}
//执行函数
(function(){
    'use strict';
    //开启老司机模式
    if(host=="blog.reimu.net"){//灵梦御所
        if(ifshow()){
            var pre = document.getElementsByTagName('pre')[0];
            if (pre) pre.style.display = 'block';
        }
    }
    //调整跳转链接
    else if(host=="hacg.li"){//琉璃神社
        var aaa=$(".entry-title a");
        for(var j=0;j<aaa.length;j++){
            var ax=aaa[j];
            var dir=ax.href.indexOf(':');
            ax.href="https"+ax.href.substring(dir);
        }
        //调整神秘代码
        var toogle = document.getElementsByClassName('toggle-box')[0];
        if (toogle) toogle.style.display = 'block';
        var oldDriver = document.getElementsByClassName('entry-content')[0];
        if(host=="sexacg.com")oldDriver=document.getElementsByTagName('p')[4];
        var childDriver = oldDriver.childNodes;
        for (var i = childDriver.length - 1; i >= 0; i--){
            var takeMe = childDriver[i].textContent.match(/(\w{40})|(([A-Za-z0-9]{2,39})( ?)[\u4e00-\u9fa5 ]{2,}( ?)+(\w{2,37})\b)/g);
            if (takeMe){
                for (j = 0; j < takeMe.length; ++j){
                    console.log(takeMe[j]);
                    var has = takeMe[j].toString().replace(/(\s|[\u4e00-\u9fa5])+/g, '').trim();
                    if (has.length >= 40){
                        var fuel = "<a href='magnet:?xt=urn:btih:" + has + "'>老司机链接</a>";
                        childDriver[i].innerHTML = childDriver[i].innerHTML.toString().replace(takeMe[j], fuel);
                    }
                }
            }
        }
    }
    else if(host=="sexacg.com"){//纯爱计划
        var getp=document.getElementsByTagName('p');
        getp[getp.length]=document.getElementsByClassName('su-quote-inner')[0];
        for(var ai=0;ai<=getp.length;ai++){
            var acgDriver=getp[ai];
            if(!acgDriver)continue;
            var acgChildDriver = acgDriver.childNodes;
            for (var ci = acgChildDriver.length - 1; ci >= 0; ci--){
                var bdtext=acgChildDriver[ci].textContent;
                var a = document.createElement("a");
                if((bdtext[0]=='/'&&bdtext[9]==' ')||(bdtext[9]==' ')){
                    if(bdtext[0]=='/'){
                        //if(!(/^(?=.*[a-z])[a-z0-9]+/ig.test(bdtext.split('/')[1].split(' ')[0])))continue;
                        a.setAttribute("href","https://pan.baidu.com/s"+bdtext.split(' ')[0]);
                    }
                    else{
                        if(!bdtext.substring(1).split(' ')[0].match(/^[a-zA-Z0-9]{0,8}$/))continue;
                        a.setAttribute("href","https://pan.baidu.com/s/"+bdtext.split(' ')[0]);
                    }
                    var bdnode = document.createTextNode("传送门    ");
                    a.appendChild(bdnode);
                    var b = document.createElement("a");
                    bdnode =document.createTextNode("提取码:"+bdtext.split(' ')[1]+"\n");
                    b.appendChild(bdnode);
                    acgChildDriver[ci].data="";
                    acgDriver.insertBefore(b,acgDriver.childNodes[ci]);
                    acgDriver.insertBefore(a,acgDriver.childNodes[ci]);
                    continue;
                }
                var takeacg = acgChildDriver[ci].textContent.match(/(\w{40})|(([A-Za-z0-9]{2,39})( ?)[\u4e00-\u9fa5 ]{2,}( ?)+(\w{2,37})\b)/g);
                if (takeacg){
                    for (var cj = 0; cj < takeacg.length; ++cj){
                        console.log(takeacg[cj]);
                        var achas = takeacg[cj].toString().replace(/(\s|[\u4e00-\u9fa5])+/g, '').trim();
                        if (achas.length >= 40){
                            a.setAttribute("href","magnet:?xt=urn:btih:" + achas);
                            var node = document.createTextNode("老司机链接   ");
                            a.appendChild(node);
                            acgDriver.appendChild(a);
                            acgChildDriver[ci].data="";
                            //return;
                        }
                    }
                }
            }
        }
    }
    else //百度云填写验证码
    {
        var sCode = hash.slice(1).trim();
        if(sCode==='')return;
        setTimeout (function (){
            var codeBox = $(conf.code),btnOk = $(conf.btn);
            codeBox.val(sCode);
            if (conf.preSubmit)
                if (conf.preSubmit (codeBox, btnOk))
                    return ;
            btnOk.click();
        }, 10);
    }
})();
var hostName = location.host.match(/\w+\.\w+$/)[0].toLowerCase();
var conf = site[hostName];

var HostArr = [];
for(var i in site) HostArr.push(i);
var HostExp = new RegExp(HostArr.join("|"),'i');

if(site.JumpUrl[host]){
    site.JumpUrl[host].each(function(){
        $(this).attr({'href':$(this).text(),'target':'blank'});
    });
}
//跳转(点击链接、前进后退)时开启老司机模式
function lsjmodeON(){
    if(urls.indexOf("archives")!=-1){
        var pret = document.getElementsByTagName('pre')[0];
        if(pret)pret.style.display='inline';
    }
    $("#attention").remove();
    urls=location.href;
    var re=urls.indexOf("archives");
    if(re!=-1){
        var pre = document.getElementsByTagName('pre')[0];
        var trytime=0;
        var itval=setInterval(function (){
            pre=document.getElementsByTagName('pre')[0];
            trytime+=1;
            if(trytime==40)clearInterval(itval);
            if(pre){
                if(pre.style.display!='inline'){
                    if(ifshow()){
                        pre.style.display='block';
                        clearInterval(itval);
                    }
                    else clearInterval(itval);
                }
            }
        },500);
    }
}
//监控点击事件
$('body').on('click', 'a', function (){
    if(host=="blog.reimu.net")lsjmodeON();
    //整合提取码和链接
    if(aiON===0)return;
    var target=this;
    if(this.hash) return;
    if(HostExp.test(this.href)&&!/(?:eyun|tieba)\.baidu\.com/i.test(this.href)){
        if(target.nextSibling&&site['codeRule'].test(target.nextSibling.textContent)){
            if(!/#/i.test(target.href)) target.href+='#'+extCode(target.nextSibling);}
        else{target.href+='#8酱';}
    }
});
//提取码
function extCode(obj){
    text=obj.textContent.trim();
    var rule=new RegExp('(?:提取|访问)[码碼]?\s*[:: ]?\\s*([a-z\\d]{4})','i');
    return rule.test(text)?text.match(rule)[1]:text.match(site['codeRule'])[1];
}
//老司机快捷键,并移除重口味提示
jQuery(document).keypress(function(e){
    if(odON==0)return;//快捷键无效
    if(e.ctrlKey && e.which == 13 || e.which == 10) {
        var pre = document.getElementsByTagName('pre')[0];
        if (pre) pre.style.display = 'block';
        $("#attention").remove();
    }
});
//支持前进后退
jQuery(document).ready(function ($) {
    if(bfON===0)return;
    if (window.history && window.history.pushState) {
        $(window).on('popstate', function () {
            var hashLocation = location.hash;
            var hashSplit = hashLocation.split("#!/");
            var hashName = hashSplit[1];
            if (hashName !== '') {
                var hash = window.location.hash;
                if (hash === '') lsjmodeON();
            }
        });
    }
});