GOG.com - Updated Thread Count in Title

Display a count of updated threads (and notifications) in the GOG favicon (and page title) and reload hourly so a browser tab can be used as an update notifier

当前为 2015-11-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GOG.com - Updated Thread Count in Title
  3. // @namespace ssokolow.com
  4. // @version 8
  5. // @description Display a count of updated threads (and notifications) in the GOG favicon (and page title) and reload hourly so a browser tab can be used as an update notifier
  6. // @contributionURL http://tinyurl.com/kfgayrh
  7. //
  8. // @match *://www.gog.com/forum
  9. //
  10. // @require https://cdnjs.cloudflare.com/ajax/libs/tinycon/0.6.3/tinycon.min.js
  11. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  12. //
  13. // @compatible firefox Developed and dogfooded on Firefox
  14. // @incompatible chrome This script itself works but Tinycon.js fails to set the favicon for unknown reasons
  15. //
  16. // @grant GM_getValue
  17. // @grant GM_setValue
  18. // @grant GM_registerMenuCommand
  19. // ==/UserScript==
  20.  
  21. // Set up hourly reload before anything that unexpected markup could break
  22. setTimeout(function() { window.location.reload(true); },
  23. GM_getValue('check_interval', 3600 * 1000));
  24.  
  25. // Initialize with values indicating a soft error
  26. var bubble_bg = '#FF8000';
  27. var unviewed_count = '!';
  28. var notification_counts = null;
  29. var needs_persist = false;
  30. var old_counts = JSON.parse(GM_getValue('notification_counts', '{}'));
  31.  
  32. /// Save a set of counts as 'stuck' so they'll get ignored next time
  33. var mark_stuck_values = function(counts) {
  34. GM_setValue('notification_counts', JSON.stringify(counts));
  35. }
  36.  
  37. /// Mark a value in old_counts to be cleared
  38. var reset_stuck_value = function(idx) {
  39. old_counts[idx] = 0;
  40. needs_persist = true;
  41. }
  42.  
  43. /// Retrieve GOG notification counts with "mark as read" support
  44. var get_notification_counts = function() {
  45. // Parse the counts and omit the total to avoid double-counting
  46. var counts = [], total = 0;
  47. $(".top-nav__item-count").slice(1).each(function() {
  48. counts.push(Number(this.textContent));
  49. });
  50.  
  51. // Implement "Mark as Read" to work around GOG's delayed dismissal
  52. for (var i = 0, len = counts.length; i < len; i++) {
  53. if (old_counts && old_counts[i] && counts[i] >= old_counts[i]) {
  54. // If the number went up, keep suppressing stuff marked as stuck
  55. total += counts[i] - old_counts[i];
  56. } else {
  57. total += counts[i];
  58. reset_stuck_value(i);
  59. }
  60. }
  61.  
  62. // Only call GM_setValue once for performance reasons
  63. if (needs_persist) {
  64. mark_stuck_values(old_counts);
  65. needs_persist = false;
  66. }
  67.  
  68. // Make accessible to the "mark as read" callback
  69. notification_counts = counts;
  70. return total;
  71. };
  72.  
  73. /// Retrieve unviewed count for favourite forum topics
  74. var get_unviewed_count = function() {
  75. var category = $(".topics .text:contains('My favourite topics')");
  76. if (category.length) { // If not some kind of "server overloaded" page...
  77. category = category.parents('h2').next('.category');
  78.  
  79. // Use an empty list of favourite topics to detect being logged out
  80. if (category.find('.item:not(.message)').length) {
  81. bubble_bg = '#9CC824';
  82. unviewed_count = category.find('.item:not(.visited) .name a').length;
  83. } else {
  84. bubble_bg = '#ff0000';
  85. unviewed_count = 'X';
  86. }
  87. }
  88. }
  89.  
  90. $(document).ready(function() {
  91. get_unviewed_count();
  92. if (unviewed_count !== 'X') {
  93. unviewed_count += get_notification_counts();
  94. }
  95.  
  96. Tinycon.setOptions({
  97. width: 7,
  98. height: 9,
  99. font: '10px arial',
  100. colour: '#ffffff',
  101. background: bubble_bg,
  102. fallback: false
  103. });
  104. Tinycon.setBubble(unviewed_count);
  105. $('title').text('[' + unviewed_count + '] ' + $('title').text());
  106.  
  107. GM_registerMenuCommand("Ignore Stuck Notification Count", function() {
  108. mark_stuck_values(notification_counts);
  109. }, 'I');
  110. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址