zhelper妙传码

通过zhelper搜索书籍点击直接复制秒传码

当前为 2022-11-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         zhelper妙传码
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  通过zhelper搜索书籍点击直接复制秒传码
// @author       伟业
// @match        https://*.v4.zhelper.net/search/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zhelper.net
// @grant        GM_xmlhttpRequest
// @connect      *
 // @license MIT
// ==/UserScript==

(async function () {
    'use strict';
    //首先获取到所有的a标签
    var a = document.getElementsByClassName(" list-group-item list-group-item-action ");
    for (var i = 0; i < a.length; i++) {
        a[i].onclick = async function (e) {
            //阻止跳转
            stop(e)
            //获取链接
            var url = this.href;
            //获取z-libary 数据id
            console.log(e);
            console.log(this.herf);
            var id = url.split("/").slice(-2)[0];
            console.log(id);
            //获取接口url
            var baseUrl = 'https://mc.zhelper.net/miaochuan/' + id
            console.log(baseUrl);
            //模拟请求接口
            var mcMark =  await getmcMarkHtml(baseUrl)
            //复制到剪切板
            copyToClip(mcMark,'秒传码'+mcMark+'复制成功');
            return false;
        }
    }

    //获取到mcMark页面
    async function getmcMarkHtml(baseurl) {
        return new Promise(function (resolve, reject) {
            GM_xmlhttpRequest({
                method: 'GET',
                url: baseurl,
                onload(xhr) {
                    console.log(xhr.responseText);
                    //解析html
                    var parser = new DOMParser();
                    var htmlDoc = parser.parseFromString(xhr.responseText, 'text/html');
                    var mark =  htmlDoc.getElementById('Input 1').value;
                    console.log(mark)
                    resolve(mark);
                }
            });
        });
    }

    //复制内容到剪切板
    function copyToClip(content, message) {
        var aux = document.createElement("input");
        aux.setAttribute("value", content);
        document.body.appendChild(aux);
        aux.select();
        document.execCommand("copy");
        document.body.removeChild(aux);
        if (message == null) {
            alert("复制成功");
        } else{
            alert(message);
        }
    }



    //禁止跳转第三方网页
    function stop(event) {
        //IE和Chrome下是window.event 火狐下是event
        event = event || window.event;
        if (event.preventDefault) { //event.preventDefault(); 取消事件的默认动作
            event.preventDefault();
        } else {
            event.returnValue = false;
        }
    };

})();