Browse Source

no message

westinyang 2 years ago
parent
commit
87915bf555
2 changed files with 60 additions and 0 deletions
  1. 59 0
      user.js/MinDoc_EXT.user.js
  2. 1 0
      user.js/README.md

+ 59 - 0
user.js/MinDoc_EXT.user.js

@@ -0,0 +1,59 @@
+// ==UserScript==
+// @name         MinDoc 扩展脚本
+// @namespace    http://tampermonkey.net/
+// @version      0.1
+// @description  个人笔记--京东脚本;
+// @author       westinyang
+// @match        http://westinyang.top:6010/docs/*
+// @match        http://192.168.1.160:6010/docs/*
+// @icon         http://westinyang.top:6010/favicon.ico
+// @grant        none
+// ==/UserScript==
+
+(function() {
+    'use strict';
+
+    // 个人笔记--京东脚本
+    window["_docs_mylib_ff84f3afb91f2ac899ac61bfd423d343"] = function() {
+        var str = "";
+        var arr = $("pre.hljs:eq(1)").text().split("\n");
+        for (var i in arr) {
+            if (arr[i].startsWith("pt_key")) {
+                str += arr[i] + "&";
+            }
+        }
+        str = str.substring(0, str.length - 1);
+        console.log("JD_COOKIE", str);
+    }
+
+    // ====================================================================================================
+
+    // 封装自定义事件
+    const bindHistoryEvent = function(type) {
+        const historyEvent = history[type];
+        return function() {
+            const newEvent = historyEvent.apply(this, arguments);   // 执行history函数
+            const e = new Event(type);  // 声明自定义事件
+            e.arguments = arguments;
+            window.dispatchEvent(e);    // 抛出事件
+            return newEvent;    // 返回方法,用于重写history的方法
+        };
+    };
+
+    // 重写history原有的方法
+    history.pushState =  bindHistoryEvent('pushState');
+    history.replaceState =  bindHistoryEvent('replaceState');
+
+    // 监听事件
+    window.addEventListener('replaceState', historyStateChange);
+    window.addEventListener('pushState', historyStateChange);
+    function historyStateChange(e) {
+        var funcName = location.pathname.replaceAll("/", "_");
+        console.log(location.pathname, funcName);
+        //console.log(window[funcName]);
+        if (window[funcName]) {
+            window[funcName]();
+        }
+    }
+    historyStateChange({});
+})();

+ 1 - 0
user.js/README.md

@@ -4,3 +4,4 @@
 - [XXQG_mp3_dl](http://westinyang.top:6020/westinyang/code-labs/raw/master/user.js/XXQG_mp3_dl.user.js) `XXQG音频下载`
 - [AutoHandleJumpLinks](http://westinyang.top:6020/westinyang/code-labs/raw/master/user.js/AutoHandleJumpLinks.user.js) `自动处理跳转外链`
 - [yinghuacd.com_adblock](http://westinyang.top:6020/westinyang/code-labs/raw/master/user.js/yinghuacd.com_adblock.user.js) `樱花动漫去广告`
+- [MinDoc_EXT](http://westinyang.top:6020/westinyang/code-labs/raw/master/user.js/MinDoc_EXT.user.js) `MinDoc 扩展脚本`