web-history.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }).catch(function (error) {
  21. alert(error);
  22. });
  23. }
  24. }
  25. function getKey() {
  26. return "t_href" + location.href;
  27. }
  28. function setTitle() {
  29. localStorage.setItem(getKey(), document.title);
  30. }
  31. function checkTitle() {
  32. return localStorage.getItem(getKey()) !== document.title
  33. }
  34. setTimeout(() => {
  35. setTitle();
  36. save();
  37. setInterval(() => {
  38. if (checkTitle()) {
  39. setTitle();
  40. save();
  41. }
  42. }, 5000)
  43. }, 5000)
  44. })();