MinDoc_EXT.user.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // ==UserScript==
  2. // @name MinDoc 扩展脚本
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  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. var html = '<blockquote class="success"><p class="liane"><strong># JD_COOKIE(动态生成)</strong></p><p class="line">'+str+'</p></blockquote>';
  26. $("pre.hljs:eq(1)").after(html);
  27. }
  28. // ====================================================================================================
  29. // 封装自定义事件
  30. const bindHistoryEvent = function(type) {
  31. const historyEvent = history[type];
  32. return function() {
  33. const newEvent = historyEvent.apply(this, arguments); // 执行history函数
  34. const e = new Event(type); // 声明自定义事件
  35. e.arguments = arguments;
  36. window.dispatchEvent(e); // 抛出事件
  37. return newEvent; // 返回方法,用于重写history的方法
  38. };
  39. };
  40. // 重写history原有的方法
  41. history.pushState = bindHistoryEvent('pushState');
  42. history.replaceState = bindHistoryEvent('replaceState');
  43. // 监听事件
  44. window.addEventListener('replaceState', historyStateChange);
  45. window.addEventListener('pushState', historyStateChange);
  46. function historyStateChange(e) {
  47. var funcName = location.pathname.replaceAll("/", "_");
  48. console.log(location.pathname, funcName);
  49. //console.log(window[funcName]);
  50. if (window[funcName]) {
  51. window[funcName]();
  52. }
  53. }
  54. historyStateChange({});
  55. })();