Greasy Fork is available in English.

Freeport7 visible sage

Brings back red sage span on FP7

  1. // ==UserScript==
  2. // @name Freeport7 visible sage
  3. // @namespace http://freeport7.org/
  4. // @version 0.0001
  5. // @description Brings back red sage span on FP7
  6. // @author 紫
  7. // @match http://freeport7.org/*
  8. // @grant GM_xmlhttpRequest
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. "use strict";
  13.  
  14. var process, addSage, postsWithSage;
  15.  
  16. addSage = function(selected_post) {
  17. var sage_span, post_id, opening_id, post_info;
  18.  
  19. sage_span = document.createElement('span');
  20. sage_span.className = 'sage';
  21. sage_span.style.cssText = `
  22. color: red;
  23. text-shadow: 0 0 2px red;
  24. font-weight: bold;
  25. margin-left: 15px;
  26. margin-right: 5px;
  27. `;
  28.  
  29. post_id = selected_post.id.replace(/^i/, '');
  30. opening_id = selected_post.dataset.openingId;
  31. post_info = selected_post.getElementsByClassName('info')[0];
  32. if (selected_post.getElementsByClassName('sage').length === 0) {
  33. post_info.insertAdjacentElement('beforeend', sage_span);
  34. GM_xmlhttpRequest({
  35. method: 'GET',
  36. url: "/" + opening_id + "/" + post_id + ".json",
  37. onload: function(response) {
  38. var resp = JSON.parse(response.responseText);
  39. if (resp.post.sage === true) {
  40. sage_span.textContent = 'sage';
  41. }
  42. }
  43. });
  44. }
  45. };
  46.  
  47. process = function() {
  48. var replies = document.getElementsByClassName('post reply');
  49. for (var i = 0, len = replies.length; i < len; i++) {
  50. addSage(replies[i]);
  51. }
  52. };
  53.  
  54. document.onload = process();
  55. document.addEventListener('page:update', function() {
  56. setTimeout(process(), 500);
  57. });
  58. })();