zhelper妙传码

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

目前為 2022-11-23 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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;
        }
    };

})();