HF Writers Features

Adds features for HF Writers team.

  1. // ==UserScript==
  2. // @name HF Writers Features
  3. // @namespace xerotic
  4. // @description Adds features for HF Writers team.
  5. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
  6. // @include *hackforums.net*
  7. // @grant GM_info
  8. // @grant GM_addStyle
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @run-at document-start
  12. // @version 0.1
  13. // ==/UserScript==
  14.  
  15. // Separator between groups: <|||>
  16. // Separator between pieces: >|||<
  17. // File (xerotic): https://dl.dropboxusercontent.com/s/teqtv03344ze5sv/format.txt
  18. // File (Sir): https://dl.dropboxusercontent.com/u/46622032/hfuss.txt
  19.  
  20. String.prototype.contains = function (arg) {
  21. return (this.indexOf(arg) >= 0) ? true : false;
  22. }
  23.  
  24. a_array = new Array();
  25. viewed_array = {};
  26. private_count = 0
  27. private_html = '';
  28. private_temp = '';
  29. announce_html = '';
  30.  
  31. function TimezoneDetect(){
  32. var dtDate = new Date('1/1/' + (new Date()).getUTCFullYear());
  33. var intOffset = 10000; //set initial offset high so it is adjusted on the first attempt
  34. var intMonth;
  35. var intHoursUtc;
  36. var intHours;
  37. var intDaysMultiplyBy;
  38. //go through each month to find the lowest offset to account for DST
  39. for (intMonth=0;intMonth < 12;intMonth++){
  40. //go to the next month
  41. dtDate.setUTCMonth(dtDate.getUTCMonth() + 1);
  42. //To ignore daylight saving time look for the lowest offset.
  43. //Since, during DST, the clock moves forward, it'll be a bigger number.
  44. if (intOffset > (dtDate.getTimezoneOffset() * (-1))){
  45. intOffset = (dtDate.getTimezoneOffset() * (-1));
  46. }
  47. }
  48. return intOffset;
  49. }
  50.  
  51. $.ajax({
  52. url: "https://dl.dropboxusercontent.com/u/46622032/hfuss.txt",
  53. }).done(function(data) {
  54. var announcements = data.split('<|||>');
  55. $.each(announcements, function(index, value) {
  56. viewed_array[value.split('>|||<')[0]] = GM_getValue('id' + value.split('>|||<')[0], 0);
  57. if(parseInt(value.split('>|||<')[1]) == 1 && viewed_array[value.split('>|||<')[0]] == 0 && !pageTitle.contains('search.php?action=results&writerid=' + value.split('>|||<')[0])) {
  58. // if() {
  59. // GM_setValue('id' + writer_id, 1);
  60. // }
  61. private_count = private_count + 1;
  62. }
  63. a_array.push(value.split('>|||<'));
  64. });
  65. if(private_count == 1) {
  66. private_html = '<div class="pm_alert writers_alert" id="writer_notice"><div><strong>You have one unread Writers message</strong> titled <a href="search.php?action=results&writerid=';
  67. } else if(private_count > 1) {
  68. private_html = '<div class="pm_alert writers_alert" id="writer_notice"><div><strong>You have ' + private_count + ' unread Writers messages.</strong> Click <a href="search.php?action=results&writerid=0" style="font-weight: bold;">Here</a> to view them.';
  69. }
  70. var installed = GM_getValue('script_installed', 0);
  71. $.each(a_array, function(index, value) {
  72. if(!installed) {
  73. GM_setValue('id' + value[0], 1);
  74. }
  75. if(parseInt(value[1]) == 1 && private_count == 1 && viewed_array[value[0]] == 0 && !pageTitle.contains('search.php?action=results&writerid=' + value[0])) {
  76. private_temp = value[0] + '" style="font-weight: bold;">' + value[3] + '</a>';
  77. } else if(parseInt(value[1]) == 2) {
  78. announce_html = announce_html + '<div class="pm_alert writers_announcement" id="writer_announce"><div style="margin-top:5px;padding-bottom:5px;">' + value[4] + '</div></div>';
  79. }
  80. });
  81. if(!installed) {
  82. GM_setValue('script_installed', 1);
  83. }
  84.  
  85. if(private_html.length > 10) {
  86. private_html = private_html + private_temp + '</div></div>';
  87. }
  88. });
  89.  
  90. pageTitle = location.href;
  91.  
  92. if(location.href.contains("search.php?action=results&writerid=")) {
  93. writer_id = parseInt(pageTitle.split('writerid=')[1]);
  94. }
  95.  
  96. /* This is ran after AJAX is ready */
  97. function ajaxFinished() {
  98. if($("#content").length > 0) {
  99. if ($("#pm_notice").length > 0){
  100. var new_div = $('<div>' + private_html + announce_html + '</div>').hide();
  101. $("#pm_notice").after(new_div);
  102. new_div.slideDown(200);
  103. } else {
  104. var new_div = $('<div>' + private_html + announce_html + '</div>').hide();
  105. $('#content').prepend(new_div);
  106. new_div.slideDown(200);
  107. }
  108. // 6-23-2014, 1:39 AM
  109. if(pageTitle.contains("search.php?action=results&writerid=")) {
  110. if(writer_id == 0) {
  111. if(a_array.length > 1) {
  112. $('.thead').attr('colspan', '3').parent().next().remove();
  113. var $page_area = $('.thead').parent();
  114. var content_html = '';
  115. $.each(a_array.reverse(), function(index, value) {
  116. // var the_time = new Date((parseInt(new String(Date.now()).substring(0,10)) + TimezoneDetect() * 10) * 1000);
  117. var the_time = new Date((parseInt(value[2]) + TimezoneDetect() * 10) * 1000);
  118. if(the_time.getHours() > 12) {
  119. var time_hours = the_time.getHours() - 11;
  120. var am_or_pm = 'PM';
  121. } else {
  122. var time_hours = the_time.getHours() + 1;
  123. var am_or_pm = 'AM';
  124. }
  125. if(the_time.getMinutes() < 10) {
  126. var time_minutes = '0' + the_time.getMinutes();
  127. } else {
  128. var time_minutes = the_time.getMinutes();
  129. }
  130. var formatted_time = (the_time.getMonth() + 1) + '-' + the_time.getDate() + '-' + the_time.getFullYear();
  131. if(parseInt(value[1]) == 1) {
  132. if(GM_getValue('id' + viewed_array[value[0]]) == 1) {
  133. var read_or_not = '<td align="center" class="trow1" width="1%"><img src="http://x.hackforums.net/images/modern_bl/old_pm.gif" alt="Old Message" title="Old Message"></td><td align="center" class="trow1" width="12%"><span class="smalltext">' + formatted_time + '</span></td>';
  134. var strong = '<a href="search.php?action=results&writerid=' + value[0] + '">' + value[3] + '</a>';
  135. } else {
  136. var read_or_not = '<td align="center" class="trow1" width="1%"><img src="http://x.hackforums.net/images/modern_bl/new_pm.gif" alt="New Message" title="New Message"></td><td align="center" class="trow1" width="12%"><span class="smalltext">' + formatted_time + '</span></td>';
  137. var strong = '<strong><a href="search.php?action=results&writerid=' + value[0] + '">' + value[3] + '</a></strong>';
  138. }
  139. content_html = content_html + '<tr>' + read_or_not + '<td class="trow1">' + strong + '</td></tr>';
  140. } else if(parseInt(value[1]) == 2) {
  141. var read_or_not = '<td align="center" class="trow1" width="1%"><img src="http://x.hackforums.net/images/modern_bl/old_pm.gif" alt="Announcement" title="Announcement"></td><td align="center" class="trow1" width="12%"><span class="smalltext">' + formatted_time + '</span></td>';
  142. content_html = content_html + '<tr>' + read_or_not + '<td class="trow1"><a href="search.php?action=results&writerid=' + value[0] + '">' + value[3] + '</a></td></tr>';
  143. }
  144. });
  145. $page_area.after(content_html);
  146. } else {
  147. var $page_area = $('.thead').first().parent().next().children().first();
  148. $page_area.html('No news Writer\'s messages');
  149. }
  150. // var $page_area = $('.thead').first().parent().next().children().first();
  151. // $page_area.html(new String(Date.now()).substring(0,10));
  152. } else if(writer_id > 0) {
  153. $.each(a_array, function(index, value) {
  154. if(writer_id == value[0]) {
  155. GM_setValue('id' + writer_id, 1);
  156. $('.thead').parent().next().remove();
  157. var $page_area = $('.thead').html('<strong>' + value[3] + '</strong>').parent();
  158. var the_time = new Date((parseInt(value[2]) + TimezoneDetect() * 10) * 1000);
  159. if(the_time.getHours() > 12) {
  160. var time_hours = the_time.getHours() - 11;
  161. var am_or_pm = 'PM';
  162. } else {
  163. var time_hours = the_time.getHours() + 1;
  164. var am_or_pm = 'AM';
  165. }
  166. if(the_time.getMinutes() < 10) {
  167. var time_minutes = '0' + the_time.getMinutes();
  168. } else {
  169. var time_minutes = the_time.getMinutes();
  170. }
  171. var formatted_time = (the_time.getMonth() + 1) + '-' + the_time.getDate() + '-' + the_time.getFullYear();
  172. $page_area.after('<tr><td class="tcat">' + formatted_time + '</td></tr><tr><td class="trow1">' + value[4] + '</td></tr>');
  173. }
  174. });
  175. }
  176. }
  177. } else {
  178. $(document).on('DOMContentLoaded', ajaxFinished);
  179. }
  180. }
  181.  
  182. function mainContentLoaded() {
  183. $('#panel').append(' | <a href="search.php?action=results&writerid=0">Writer\'s Messages</a>');
  184. }
  185.  
  186. GM_addStyle(".writers_alert { border-top:1px solid gold !important; border-bottom:1px solid gold !important; }");
  187. GM_addStyle(".writers_announcement { border-top:1px solid gold !important; border-bottom:1px solid gold !important; min-height:30px !important; }");
  188.  
  189. $(document).on('DOMContentLoaded', mainContentLoaded);
  190.  
  191. $(document).bind('ajaxComplete', function(){
  192. ajaxFinished();
  193. });