web-history.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // @require https://cdn.bootcdn.net/ajax/libs/js-cookie/3.0.1/js.cookie.min.js
  11. // ==/UserScript==
  12. (async () => {
  13. function save() {
  14. if (window.top.location.href == window.location.href) {
  15. axios.post(`https://web_history.tianyunperfect.cn/history/insert`, {
  16. "title": document.title,
  17. "url": location.href,
  18. "user_id": 1
  19. }).then(res => {
  20. console.log(res.data);
  21. }).catch(function (error) {
  22. alert(error);
  23. });
  24. }
  25. }
  26. function getKey() {
  27. return "t_href_" + location.href;
  28. }
  29. function setTitle() {
  30. Cookies.set(getKey(), document.title);
  31. }
  32. function checkTitle() {
  33. return Cookies.get(getKey()) !== document.title
  34. }
  35. setTimeout(() => {
  36. setTitle();
  37. save();
  38. setInterval(() => {
  39. if (checkTitle()) {
  40. setTitle();
  41. save();
  42. }
  43. }, 5000)
  44. }, 5000)
  45. })();