tellonym.me guest

Load tellonym.me Tells without Login

目前为 2022-01-03 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name tellonym.me guest
  3. // @version 1.0.0
  4. // @description Load tellonym.me Tells without Login
  5. // @author TalkLounge (https://github.com/TalkLounge)
  6. // @namespace https://github.com/TalkLounge/tellonym.me-guest
  7. // @license MIT
  8. // @match https://tellonym.me/*
  9. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.slim.min.js
  10. // @require https://cdn.jsdelivr.net/npm/axios@0.24.0/dist/axios.min.js
  11. // @require https://cdn.jsdelivr.net/npm/luxon@2.3.0/build/global/luxon.min.js
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17. var lastUrl;
  18. var counter;
  19. var isProfilePage;
  20. var isProfilePageLoaded;
  21. var user;
  22. var pos;
  23. var ul;
  24. var li;
  25.  
  26. async function loadTells() {
  27. const data = await axios.get(`https://api.tellonym.me/profiles/name/${user}?limit=25&pos=${pos}`);
  28. const answers = data.data.answers;
  29. if (!answers.length) {
  30. return true;
  31. }
  32.  
  33. for (var i = 0; i < answers.length; i++) {
  34. if (answers[i].type == "AD") { // Do not display ads
  35. continue;
  36. }
  37.  
  38. var $html = $(li.prop("outerHTML"));
  39. $html.find("span").eq(0).text(answers[i].tell); // Question
  40. $html.find("span").eq(1).text(answers[i].answer); // Answer
  41. $html.find("[italic='false']").parent().parent().children().eq(1).text(luxon.DateTime.fromISO(answers[i].createdAt).toRelative()); // Time
  42. ul.append($html);
  43. }
  44. }
  45.  
  46. async function scroll() {
  47. const scrollbar = ul.parent();
  48. if (scrollbar.prop("scrollTop") / scrollbar.prop("scrollHeight") > 0.75) { // Load more tells when scrolled down
  49. pos += 25;
  50. if (await loadTells()) { // End of tells reached
  51. isProfilePage = false;
  52. }
  53. }
  54. }
  55.  
  56. async function init() {
  57. if (lastUrl != window.location.href) { // URL changed
  58. counter = 1;
  59. isProfilePage = true;
  60. isProfilePageLoaded = false;
  61. }
  62.  
  63. if (!isProfilePage) { // Page is no profile page
  64. return;
  65. } else if (isProfilePageLoaded) { // Page is profile page, load more tells when scrolled down
  66. scroll();
  67. return;
  68. }
  69.  
  70. lastUrl = window.location.href;
  71.  
  72. var localUl = $("span[data-radium=true]").first().parent().parent().parent().parent().parent().parent().parent().parent().parent();
  73. const localLi = localUl.children().eq(1);
  74.  
  75. if (!localLi.length) { // Page not loaded completely
  76. counter++;
  77. if (counter >= 20) { // Timeout after 10 seconds. Probably not a profile page
  78. isProfilePage = false;
  79. }
  80. return;
  81. }
  82. isProfilePage = true;
  83. isProfilePageLoaded = true;
  84.  
  85. try { // Remove preview tells
  86. for (var j = 1; j <= 10; j++) {
  87. localUl.children().eq(1).remove();
  88. }
  89. } catch(e) {}
  90.  
  91. user = window.location.href.split("/")[3];
  92. pos = 0;
  93. ul = localUl;
  94. li = localLi;
  95. await loadTells();
  96.  
  97. try { // Remove login banner
  98. $("img[width='28']").parent().parent().remove();
  99. } catch(e) {}
  100. }
  101.  
  102. window.setInterval(init, 500);
  103. })();