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 pinned 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 7
  5. // @description Display a count of updated threads (and notifications) in the GOG favicon (and page title) and reload hourly so a pinned 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); }, 3600 * 1000);
  23.  
  24. // Initialize with values indicating a soft error
  25. var bubble_bg = '#FF8000';
  26. var unviewed_count = '!';
  27. var notification_counts = null;
  28. var needs_persist = false;
  29. var old_counts = JSON.parse(GM_getValue('notification_counts', '{}'));
  30.  
  31. /// Save a set of counts as 'stuck' so they'll get ignored next time
  32. var mark_stuck_values = function(counts) {
  33. GM_setValue('notification_counts', JSON.stringify(counts));
  34. }
  35.  
  36. /// Mark a value in old_counts to be cleared
  37. var reset_stuck_value = function(idx) {
  38. old_counts[idx] = 0;
  39. needs_persist = true;
  40. }
  41.  
  42. /// Retrieve GOG notification counts with "mark as read" support
  43. var get_notification_counts = function() {
  44. // Parse the counts and omit the total to avoid double-counting
  45. var counts = [], total = 0;
  46. $(".top-nav__item-count").slice(1).each(function() {
  47. counts.push(Number(this.textContent));
  48. });
  49.  
  50. // Implement "Mark as Read" to work around GOG's delayed dismissal
  51. for (var i = 0, len = counts.length; i < len; i++) {
  52. if (old_counts && old_counts[i] && counts[i] >= old_counts[i]) {
  53. // If the number went up, keep suppressing stuff marked as stuck
  54. total += counts[i] - old_counts[i];
  55. } else {
  56. total += counts[i];
  57. reset_stuck_value(i);
  58. }
  59. }
  60.  
  61. // Only call GM_setValue once for performance reasons
  62. if (needs_persist) {
  63. mark_stuck_values(old_counts);
  64. needs_persist = false;
  65. }
  66.  
  67. // Make accessible to the "mark as read" callback
  68. notification_counts = counts;
  69. return total;
  70. };
  71.  
  72. /// Retrieve unviewed count for favourite forum topics
  73. var get_unviewed_count = function() {
  74. var category = $(".topics .text:contains('My favourite topics')");
  75. if (category.length) { // If not some kind of "server overloaded" page...
  76. category = category.parents('h2').next('.category');
  77.  
  78. // Use an empty list of favourite topics to detect being logged out
  79. if (category.find('.item:not(.message)').length) {
  80. bubble_bg = '#9CC824';
  81. unviewed_count = category.find('.item:not(.visited) .name a').length;
  82. } else {
  83. bubble_bg = '#ff0000';
  84. unviewed_count = 'X';
  85. }
  86. }
  87. }
  88.  
  89. $(document).ready(function() {
  90. get_unviewed_count();
  91. if (unviewed_count !== 'X') {
  92. unviewed_count += get_notification_counts();
  93. }
  94.  
  95. Tinycon.setOptions({
  96. width: 7,
  97. height: 9,
  98. font: '10px arial',
  99. colour: '#ffffff',
  100. background: bubble_bg,
  101. fallback: false
  102. });
  103. Tinycon.setBubble(unviewed_count);
  104. $('title').text($('title').text() + ' (' + unviewed_count + ')');
  105.  
  106. GM_registerMenuCommand("Ignore Stuck Notification Count", function() {
  107. mark_stuck_values(notification_counts);
  108. }, 'I');
  109. });

QingJ © 2025

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