12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- // ==UserScript==
- // @name MinDoc 扩展脚本
- // @namespace http://tampermonkey.net/
- // @version 0.2
- // @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);
- var html = '<blockquote class="success"><p class="liane"><strong># JD_COOKIE(动态生成)</strong></p><p class="line">'+str+'</p></blockquote>';
- $("pre.hljs:eq(1)").after(html);
- }
- // ====================================================================================================
- // 封装自定义事件
- 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({});
- })();
|