网盘自动填写密码【增强版】【已停止维护】

网盘自动填写提取密码【增强版】+网盘超链接与提取码融合。\n(该脚本已停止维护,推荐使用效果更好的【威力加强版】:https://greasyfork.org/zh-CN/scripts/29762 。\n本脚本会强制推送一次新版本,如果你选择了不再推送,只要不清除浏览器数据理论是不会再推送了)

< Feedback on 网盘自动填写密码【增强版】【已停止维护】

Question/comment

§
Posted: 2016-06-20

PR一个版本,遍历上级元素查找密码

// ==UserScript==
// @name            网盘自动填写密码【增强版】
// @description     网盘自动填写提取密码【增强版】+网盘超链接与提取码融合。
// @author          极品小猫
// @namespace       http://www.cnblogs.com/hkmhd/
// @homepage        https://greasyfork.org/scripts/13463
// @supportURL      https://greasyfork.org/scripts/13463/feedback
// @version         2.2.0
// @date            2016.03.19
// 
// 支持的网盘
// @include         http://pan.baidu.com/share/init?*
// @include         http://yun.baidu.com/share/init?*
// @include         http://www.kuaipan.cn/file/id_*
// @include         /^https?://.+\.yunpan.cn/lk//
// @include         http://vdisk.weibo.com/lc/*
// @include         http://*
// @include         https://*
// 
// @exclude         /https?://www.baidu.com/(?:s|baidu)\?/
// @exclude         https://*.evernote.com/*
// @exclude         https://*.yinxiang.com/*
// @require         http://code.jquery.com/jquery-2.1.4.js
// @grant           unsafeWindow
// @encoding        utf-8
// @run-at          document-idle
// ==/UserScript==

var urls=location.href;
var hash=location.hash;
var host=location.hostname.replace(/^www\./i,'').toLowerCase();
unsafeWindow.eve = Event;

var site = {
    'yunpan.cn': {
        chk:  /^[a-z0-9]{4}$/,
        code: '.pwd-input',
        btn:  '.submit-btn'
    },
    'baidu.com': {
        chk:  /^[a-z0-9]{4}$/,
        code: '#accessCode',
        btn:  '#submitBtn'
    },
    'kuaipan.cn': {
        chk:  /^[a-z0-9]{6}$/i,
        code: '#pwdContaier .txt',
        btn:  '#btnOK',
        preSubmit: function (codeBox, okBtn) {
            $('#pwdContaier .bold').textContent = '请手动单击确认按钮然后刷新页面';
        }
    },
    'weibo.com': {
        chk:  /^[a-z0-9]{4}$/i,
        code: '#keypass',
        btn:  '.search_btn_wrap > a',
        preSubmit: function (codeBox, okBtn) {unsafeWindow.$("#validate").submit();}
    },
    'codeRule':/(?:提取|密码?|访问|艾)[码碼]?[:: ]?\s*([a-z\d]{4})/i
};

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');    //生成校验超链接的正则
var maxParent = 5;      // 最多遍历几层上级元素

if(conf){   //网盘页面填密码登录
    // 抓取提取码
    var sCode = hash.slice(1).trim();

    // 调试用,检查是否为合法格式
    if (!conf.chk.test(sCode)) {
        console.log('没有 Key 或格式不对');
    } else {
        console.log ('抓取到的提取码: %s', sCode);
    }

        // 加个小延时
        setTimeout (function () {
            // 键入提取码并单击「提交」按钮,报错不用理。
            var codeBox = $(conf.code),
                btnOk = $(conf.btn);

            codeBox.val(sCode);     //填写验证码

            if (conf.preSubmit)
                if (conf.preSubmit (codeBox, btnOk))
                    return ;

            btnOk.click();
        }, 10);
} else {
    $('A').click(function(){
        var target=this,
            parent,
            i = 0;
        //var target=event.target.tagName==='A'?event.target:event.target.parentNode;
        //console.log(this.parentNode.textContent);
        if(HostExp.test(this.href)){
            if(site['codeRule'].test(target.textContent)){
                console.log('在当前超链接的对象中查找密码');
                target.href+='#'+extCode(target);
            } else if(target.nextSibling&&site['codeRule'].test(target.nextSibling.textContent)){
                console.log('密码在超链接后面的兄弟元素中');
                if(!/#/i.test(target.href)) target.href+='#'+extCode(target.nextSibling);
            } else {
                parent = target;
                while(i<maxParent) {
                    i++;
                    parent = parent.parentNode;
                    console.log('遍历上级目录查找密码:'+ i);
                    if(site['codeRule'].test(parent.textContent)) {
                        target.href+='#'+extCode(parent);
                        break;
                    }
                    if(parent==document.body) break;
                }
            }
            /* else if(site['codeRule'].test(target.parentNode.textContent)){
                console.log('从父对象中查找密码');
                if(!/#/i.test(target.href)) target.href+='#'+extCode(target.parentNode);
            } else {
                console.log('从父对象中查找密码');
                if(!/#/i.test(target.href)) target.href+='#'+extCode(document.body);
            }*/
        // console.log(site['codeRule']);
        // console.log(document.body.textContent);
        }
    })
}

function extCode(obj){
    text=obj.textContent.trim();
    var rule=new RegExp('(?:提取|访问)[码碼]?[:: ]?\\s*([a-z\\d]{4})','i');
    return rule.test(text)?text.match(rule)[1]:text.match(site['codeRule'])[1]
}
§
Posted: 2016-06-20

推荐:

  1. Gist 提交原始代码
  2. 提交你的修改后代码

这样能方便查看哪里修改了。

§
Posted: 2016-06-24

https://gist.github.com/mudoo/fdf472c4d8e15fd1d66748d215e1cd21/revisions
host匹配改了,避免正则匹配不到报错
直接从document.body获取密码不合理,body内容那么多,改为向上遍历元素获取

极品小猫Author
§
Posted: 2016-08-01
https://gist.github.com/mudoo/fdf472c4d8e15fd1d66748d215e1cd21/revisions
host匹配改了,避免正则匹配不到报错
直接从document.body获取密码不合理,body内容那么多,改为向上遍历元素获取

感谢建议,因为当初就是觉得逐级向上遍历很麻烦,效率也不是特别高,效果好不了多少,所以就偷懒直接body了。
例如一些Table类的,密码和链接处于两个TR之间,也一样会提取错误。
你的Host匹配修改很好,采纳了新代码,感谢分享。

Post reply

Sign in to post a reply.