【油猴脚本】鼠标选中跳转蓝奏云有效链接及自动填写提取码

简述

鼠标选中蓝奏云链接时会将链接转化为有效链接并显示跳转按钮,如果选中内容包括提取码则会在对应的网页自动填充。
地址:鼠标选中跳转蓝奏云有效链接及自动填写提取码

功能

在鼠标选中的文字是蓝奏云链接时触发脚本,脚本将从选中文字中提取蓝奏云链接及密码,并且将链接转化为以lanzoui.com为顶级域名地址,然后在鼠标附近显示实时信息,同时也显示一个跳转链接 前往-> 及一个关闭显示信息的按钮。在点下前往-> 后自动关闭选中文本页面的显示信息,同时打开一个地址是对应链接的新窗口,如果之前选中的内容包含密码,则会自动填充并确认密码。同时当前页面对应的蓝奏云资源的密码也会保留在本地,当你下次再打开这个链接时会自动填充密码(前提是保存的数据没有被清除,注意这个密码不是像Chrome之类浏览器的保存密码的形式,所以你不会在浏览器管理面板找到密码)

使用

随便选择一个不包含蓝奏云链接的内容(识别条件是含有lanzou)时的效果如下图所示:
鼠标选中跳转蓝奏云有效链接及自动填写提取码1
选中一个蓝奏云链接但不包含密码的内容时的效果如下图所示:
鼠标选中跳转蓝奏云有效链接及自动填写提取码2
选中一个蓝奏云链接并包含密码的内容时的效果如下图所示:
鼠标选中跳转蓝奏云有效链接及自动填写提取码3
在第一次自动填充密码后再次打开该页面时的效果如下图所示(太快了可能看不清):
鼠标选中跳转蓝奏云有效链接及自动填写提取码4

0.1.0 版本源码

// ==UserScript==
// @name         鼠标选中跳转蓝奏云有效链接及自动填写提取码
// @namespace    https://coycs.com/
// @version      0.1.0
// @description  鼠标选中蓝奏云链接时会将链接转化为有效链接并显示跳转按钮,如果选中内容包括提取码则会在对应的网页自动填充。
// @author       coycs
// @match        http://*/*
// @match        https://*/*
// @match       *.lanzoui.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict'


    // 获取鼠标位置
    var movex;
    var movey;
    function mousemove(e) {
        e = e || window.event;
        if (e.clientX || e.clientY) {
            movex = e.clientX;
            movey = e.clientY
        }
    }
    document.onmousemove = mousemove;

    // 展示有效链接及提取码
    function show(href, password) {
        var relay = "";
        if (password != "") {
            relay = href + "coycs" + password + "coycs";
        } else {
            relay = href;
        }
        if (!document.getElementsByClassName("popWindow")[0]) {
            // 创建节点
            var div = document.createElement('div');
            div.setAttribute("style", "background:linear-gradient(#00b09b, #96c93d);position:fixed;padding:20px;z-index:10000;");
            div.setAttribute("class", "popWindow");
            div.setAttribute("color", "#fff");
            div.style.left = movex + 30 + "px";
            div.style.top = movey + 30 + "px";
            document.getElementsByTagName("body")[0].appendChild(div);
            div.innerHTML = `<p padding="5px"  margin-bottom="5px">链接:<span id="hrefText">${href}</span></p>
            <p padding="5px" id="nodePassword" margin-bottom="5px">提取码:<span id="passwordText">${password}</span></p>
            <p id="actionBtns"><a id="hrefBtn" href="${relay}" target="_blank" padding="5px">前往-></a>
            <button id="closeBtn" padding="5px">关闭</button></p>`;
            var actionBtns = document.getElementById("actionBtns");
            actionBtns.setAttribute("style", "display: flex;flex-direction: row;justify-content: space-between;");
            // 前往按钮
            var hrefBtn = document.getElementById("hrefBtn");
            hrefBtn.addEventListener("click", function () {
                window.getSelection().removeAllRanges();
                document.getElementsByClassName("popWindow")[0].remove();
            })
            // 关闭按钮
            var closeBtn = document.getElementById("closeBtn");
            closeBtn.setAttribute("style", "background-color:#96c93d;border-style:none;")
            closeBtn.addEventListener("click", function () {
                window.getSelection().removeAllRanges();
                document.getElementsByClassName("popWindow")[0].remove();
            })
        } else {
            var hrefText = document.getElementById("hrefText");
            var passwordText = document.getElementById("passwordText");
            hrefBtn = document.getElementById("hrefBtn");
            hrefText.innerHTML = href;
            passwordText.innerHTML = password;
            hrefBtn.setAttribute("href", `${relay}`);
        }
    }


    // 选取文字触发
    var select = function () {
        if (window.getSelection && window.getSelection().toString().indexOf("lanzou") != -1) {
            // 字符串初处理
            var string1 = window.getSelection().toString();
            console.log("string1:" + string1);
            var string2 = string1.substring(string1.indexOf("http"), string1.length).replace(/\s*/g, "");
            console.log("string2:" + string2);
            // 获取链接部分
            var href = "";
            if (string2.match(/[^\x00-\xff]/g)) {
                href = string2.substring(0, string2.indexOf(string2.match(/[^\x00-\xff]/g)[0]));
            } else {
                href = string2;
            }
            var string3 = href;
            console.log("href:" + href);
            var domin = href.split("/")[2].split('.').slice(-2).join('.');
            var dominR = "lanzoui.com";
            href = href.replace(domin, dominR).replace(/[\x22\x27-\x29\x2c\x3b\x5b-\x5e\x60\x7b-\x7f]/g, "");
            console.log("href:" + href);
            // 获取提取码部分
            var password = string2.replace(string3, "").replace(/[^\x00-\xff]/g, "").replace(":", "");
            console.log("password:" + password);
            show(href, password);
        }
    }
    // 选中链接及提取码部分
    document.addEventListener("mouseup", select);





    // 自动填写提取码部分
    // 获取网页链接
    var url = document.location.href;
    var urlDomin = url.split("/")[2].split('.').slice(-2).join('.');
    // 定义目标网站
    var urlDominR = "lanzoui.com"
    // 跳转到顶级域名为目标网站的页面
    if (urlDomin == "lanzous.com"||urlDomin == "lanzouw.com"||urlDomin == "lanzoux.com") {
        location.href = url.replace(url.split("/")[2].split('.').slice(-2).join('.'), urlDominR);
    }
    // 自动填写提取码
    if (url.indexOf(urlDominR) != -1) {
        var pwd = document.getElementById("pwd");
        if (url.indexOf("coycs") != url.lastIndexOf("coycs")) {
            var link = url.substring(0, url.indexOf("coycs"));
            var psw = url.substring(url.indexOf("coycs") + 5, url.lastIndexOf("coycs"));
            localStorage.setItem(link, psw);
            window.location.href = link;
        }
        if (pwd) {
            var passwddiv_btn = document.getElementsByClassName("passwddiv-btn")[0];
            var btnpwd = document.getElementsByClassName("btnpwd")[0];
            // 输入提取码
            pwd.value = localStorage.getItem(url);
            // 确认提取码
            if (passwddiv_btn) {
                passwddiv_btn.click();
            } else if (btnpwd) {
                btnpwd.click();
            }
            // localStorage.removeItem(url);
        }
    }
})();

注意

识别并提取蓝奏云链接是有一定条件的,因为蓝奏云链接不仅有自定义二级域名,顶级域名还有好几个,还有的是http或者是https,所以比如链接开头不包含http的就识别不到,还有其他个别的情况也会识别错误。但我也考虑了比较多的情况了,所以正常使用应该没有太大问题,选中提取出的链接错误时可以再仔细地选择文本,建议只选择蓝奏云链接,不要把其他内容也选进来了。

还有是关于密码的问题,这个脚本识别密码能力也是有限的,但官方的格式应该没有什么问题,就是下面这种类型的:https://coycs.lanzouw.com/iq2kJxo2s8f 密码:biux,因为有的人会说密码、提取码、验证码等等,而且密码位置也五花八门,还有其他很多干扰项影响识别。如果你实在懒得自己输密码,可以组成官方格式,然后随便在哪个网页的哪个输入框内粘贴格式重组好的然后再用插件识别,比如输在百度搜索的搜索框里。这样下次打开对应蓝奏云资源的网页时就会自动填写密码。

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值