web-history.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // ==UserScript==
  2. // @name T-All-历史记录
  3. // @author tianyunperfect
  4. // @description 简介
  5. // @version 1.0.0
  6. // @update 2021-07-08 16:16:14
  7. // @match *://*/*
  8. // @require https://git.tianyunperfect.cn/tianyunperfect/web-base/raw/master/tmp/monkey/util.js?a=2022年05月15日
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js
  10. // ==/UserScript==
  11. (async () => {
  12. function save() {
  13. if (window.top.location.href == window.location.href) {
  14. axios.post(`https://web_history.tianyunperfect.cn/history/insert`, {
  15. "title": document.title,
  16. "url": location.href,
  17. "user_id": 1
  18. }).then(res => {
  19. console.log(res.data);
  20. });
  21. }
  22. }
  23. function getKey() {
  24. return "t_href" + location.href;
  25. }
  26. function setTitle() {
  27. localStorage.setItem(getKey(), document.title);
  28. }
  29. function checkTitle() {
  30. return localStorage.getItem(getKey()) !== document.title
  31. }
  32. setTimeout(() => {
  33. setTitle();
  34. save();
  35. setInterval(() => {
  36. if (checkTitle()) {
  37. setTitle();
  38. save();
  39. }
  40. }, 5000)
  41. }, 5000)
  42. })();