MinDoc_EXT.user.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // ==UserScript==
  2. // @name MinDoc 扩展脚本
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 个人笔记--京东脚本;
  6. // @author westinyang
  7. // @match http://westinyang.top:6010/docs/*
  8. // @match http://192.168.1.160:6010/docs/*
  9. // @icon http://westinyang.top:6010/favicon.ico
  10. // @grant none
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14. // 个人笔记--京东脚本
  15. window["_docs_mylib_ff84f3afb91f2ac899ac61bfd423d343"] = function() {
  16. var str = "";
  17. var arr = $("pre.hljs:eq(1)").text().split("\n");
  18. for (var i in arr) {
  19. if (arr[i].startsWith("pt_key")) {
  20. str += arr[i] + "&";
  21. }
  22. }
  23. str = str.substring(0, str.length - 1);
  24. console.log("JD_COOKIE", str);
  25. }
  26. // ====================================================================================================
  27. // 封装自定义事件
  28. const bindHistoryEvent = function(type) {
  29. const historyEvent = history[type];
  30. return function() {
  31. const newEvent = historyEvent.apply(this, arguments); // 执行history函数
  32. const e = new Event(type); // 声明自定义事件
  33. e.arguments = arguments;
  34. window.dispatchEvent(e); // 抛出事件
  35. return newEvent; // 返回方法,用于重写history的方法
  36. };
  37. };
  38. // 重写history原有的方法
  39. history.pushState = bindHistoryEvent('pushState');
  40. history.replaceState = bindHistoryEvent('replaceState');
  41. // 监听事件
  42. window.addEventListener('replaceState', historyStateChange);
  43. window.addEventListener('pushState', historyStateChange);
  44. function historyStateChange(e) {
  45. var funcName = location.pathname.replaceAll("/", "_");
  46. console.log(location.pathname, funcName);
  47. //console.log(window[funcName]);
  48. if (window[funcName]) {
  49. window[funcName]();
  50. }
  51. }
  52. historyStateChange({});
  53. })();