web-history.js 1.5 KB

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