Per Thread Status

This adds a custom status field to the list of threads in the forum view. This should work on both SB/SV and probably other XenForo based forums with a bit of tweaking.

目前为 2020-06-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Per Thread Status
  3. // @namespace https://greasyfork.org/users/2562
  4. // @version 0.75
  5. // @description This adds a custom status field to the list of threads in the forum view. This should work on both SB/SV and probably other XenForo based forums with a bit of tweaking.
  6. // @author arctica
  7. // @match https://forums.spacebattles.com/forums/*
  8. // @match https://forums.sufficientvelocity.com/forums/*
  9. // @match https://forums.spacebattles.com/watched/threads*
  10. // @match https://forums.sufficientvelocity.com/watched/threads*
  11. // @grant none
  12. // ==/UserScript==
  13. function append_info() {
  14. // set the threads to an array var for use
  15. var threads_array = document.getElementsByClassName("js-inlineModContainer");
  16. // set the total number of threads
  17. var threads_total = threads_array.length;
  18. // loop through all the threads
  19. // and add an the thread id as an ID
  20. for (var i = 0; i < threads_total; i++) {
  21. // create an array based on the class list
  22. var temp_array = Array.from(threads_array[i].classList);
  23. // find the className and then read only the thread id
  24. var temp_number = temp_array[temp_array.findIndex(element => element.includes("js-threadListItem-"))].substring(18);
  25. // set the thread id to the ID of the thread html element
  26. threads_array[i].id = temp_number;
  27. // set the status from the localstorage
  28. var temp_status = check_status(temp_number);
  29. // set the opacatiy, if status not set set to 0.25 otherwise set to 0.75
  30. var temp_opacity = (temp_status == "<i>Not Set</i>") ? 0.25 : 0.75;
  31. // add the custom status to the page
  32. threads_array[i].getElementsByClassName("structItem-minor")[0].innerHTML += "<div style='float:right; opacity: " + temp_opacity + ";' class='PTS-Status');\">" + temp_status + "</div>";
  33. // set click event to run allowing change of status
  34. document.getElementById(temp_number).getElementsByClassName("PTS-Status")[0].addEventListener("click", change_status(temp_number));
  35. }
  36. }
  37.  
  38. function change_status(temp_id) {
  39. return function() {
  40. //grab the current custom status
  41. var temp_current = document.getElementById(temp_id).getElementsByClassName("PTS-Status")[0].innerText;
  42. //create user input box
  43. var temp_prompt = prompt("Please input a custom status.\nIf set to \"Not Set\" then the custom status will be removed.", temp_current);
  44. // if the user kept the Not Set setting
  45. if (temp_prompt == "Not Set") {
  46. // update value on document keeping it in italics
  47. document.getElementById(temp_id).getElementsByClassName("PTS-Status")[0].innerHTML = "<i>Not Set</i>";
  48. // update the opacity
  49. document.getElementById(temp_id).getElementsByClassName("PTS-Status")[0].style.opacity = 0.25;
  50. // remove the updated value
  51. remove_status(temp_id);
  52. // if the prompt isn't null and not just spaces or blank
  53. } else if (temp_prompt != null & temp_prompt.trim().length) {
  54. // update the status
  55. document.getElementById(temp_id).getElementsByClassName("PTS-Status")[0].innerHTML = temp_prompt;
  56. // update the opacity
  57. document.getElementById(temp_id).getElementsByClassName("PTS-Status")[0].style.opacity = 0.75;
  58. // store the id/status in the localstorage
  59. store_status(temp_id, temp_prompt);
  60. }
  61. };
  62. }
  63.  
  64. function store_status(temp_id, temp_status) {
  65. // create array based on thread id and status value
  66. var temp_thread = [temp_id, temp_status];
  67. // create array of threads for use, if already exsiting will be overwritten
  68. var temp_array = [temp_thread];
  69. // check to see if something was stored, if yes edit.
  70. if (localStorage["pts-threads"] != null) {
  71. // update temp array based on local storage
  72. temp_array = JSON.parse(localStorage["pts-threads"]);
  73. // check to see if thread id exists in array. If it does, update the existing data; otherwise add the thread info into the array
  74. (temp_array.find(element => element[0] == temp_id) != null) ? temp_array.find(element => element[0] == temp_id)[1] = temp_status : temp_array.push(temp_thread);
  75. }
  76. // update the localstorage
  77. localStorage["pts-threads"] = JSON.stringify(temp_array);
  78. }
  79.  
  80. function remove_status(temp_id) {
  81. // check to see if something was stored
  82. if (localStorage["pts-threads"] != null) {
  83. var temp_array = JSON.parse(localStorage["pts-threads"]);
  84. // if the temp_id can be found in the stored array
  85. if (temp_array.find(element => element[0] == temp_id) != null) {
  86. // remove the id/status from the array
  87. temp_array.splice(temp_array.findIndex(element => element[0] == temp_id), 1);
  88. // update the local storage
  89. localStorage["pts-threads"] = JSON.stringify(temp_array);
  90. }
  91. }
  92. }
  93.  
  94. function check_status(temp_id) {
  95. // Set the status to not set
  96. var temp_status;
  97. // check to see if the localstorage has been used yet. if yes search for thread ID
  98. if (localStorage["pts-threads"] != null) {
  99. var temp_array = JSON.parse(localStorage["pts-threads"]);
  100. // if that thread id is already in use, if it is use the exsiting data; otherwise the status is not set.
  101. (temp_array.find(element => element[0] == temp_id) != null) ? temp_status = temp_array.find(element => element[0] == temp_id)[1] : temp_status = "<i>Not Set</i>";
  102. // if local storage is not in use
  103. } else {
  104. // set the status to not set
  105. temp_status = "<i>Not Set</i>";
  106. }
  107. return temp_status;
  108. }
  109. //Give threads an ID of the thread id number on load //window.onload = append_id()
  110. append_info();