GA feed & notifies

Быстрый доступ к ленте и уведомлениям без перехода на отдельную страницу.

  1. // ==UserScript==
  2. // @name GA feed & notifies
  3. // @namespace glav.su
  4. // @description Быстрый доступ к ленте и уведомлениям без перехода на отдельную страницу.
  5. // @include http://glav.su/*
  6. // @include https://glav.su/*
  7. // @version 2.2
  8. // @grant none
  9. // ==/UserScript==
  10. //var bcapts = {feed: 'лента', notifies: 'уведомления', pm: 'сообщения'},
  11. var bcapts = {feed: '', notifies: ''},
  12. // lUserPanel = '#lUserPanel',
  13. lUserPanel = '.l-up-f',
  14. $btn = {}, box_width = '1100px', box_height = '500px';
  15. //HTML box
  16. $(".lUserPanelFloat").css({'z-index': "90"});
  17. var $nfm_box = $('<div id="nfm_box">')
  18. .css({ 'border': "1px solid #aaa", 'border-radius': "5px", 'width': box_width, 'height': box_height,
  19. 'background-color': "#ccc", 'position': "absolute", 'box-shadow': "3px 3px 10px #444",
  20. 'overflow': "hidden", 'resize': "both", 'display': "none", })
  21. .append($('<div id="nfm_header">')
  22. .css({ 'text-align': "right", 'padding': "2px", 'height': "22px",
  23. 'background-color': "#0055e5", 'margin': "3px", 'border-radius': "3px 3px 0 0", })
  24. .append($('<a href="javascript:void(0);" id="nfm_close" title="Закрыть">&times;</a>')
  25. .css({ 'width': "22px", 'height': "20px", 'border-radius': "3px", 'background-color': "transparent",
  26. 'text-align': "center", 'font-size': "24px", 'font-weight': "bold", 'text-decoration': "none",
  27. 'color': "#fff", 'display': "block", 'float': "right", 'padding-top': "2px", })
  28. .hover(function(){
  29. $(this).css({'background-color': "#e00"});
  30. }, function(){
  31. $(this).css({'background-color': "transparent"});
  32. })
  33. .click(function(){
  34. box_close();
  35. })
  36. )
  37. .append($('<span id="nfm_title">')
  38. .css({ 'display': "block", 'width': "100%", 'text-align': "center", })
  39. )
  40. )
  41. .append($nfm_scroller = $('<div id="nfm_scroller">')
  42. .css({ 'overflow-y': "scroll", 'position': "absolute", 'bottom': "16px", 'top': "32px", 'right': "3px",
  43. 'left': "3px", 'background-color': "#fff", 'border': "1px solid #bbb", })
  44. .scroll(function(){
  45. //$(lUserPanel+" div[id$=ViewContainer]:visible").hide();
  46. })
  47. .append($nfm_content = $('<div id="nfm_content">')
  48. .css({ 'color': "#000", 'height': "auto", 'padding': "10px", 'display': "block", })
  49. )
  50. )
  51. .appendTo( $(lUserPanel) );
  52. var $sandbox = ((s=$("#sandbox")).length == 1)?
  53. s : $('<div id="sandbox" style="display: none;">').appendTo( $(document.body) );//песочница
  54. // Обновление кнопок "лента", "уведомление", "сообщение"
  55. function updateButton(bt, count){
  56. //var bc = ['redButton', 'blueButton'], sw = +(count > 0);
  57. var bc = ['c-b-r', 'c-b-b'], sw = +(count > 0);
  58. $btn[bt].removeClass(bc[sw]).addClass(bc[+(!sw)]).html( bcapts[bt] + (sw? '<span>' + count + '</span>' : '') );
  59. }
  60.  
  61. function box_close(){
  62. //$(lUserPanel+" div[id$=ViewContainer]").remove();
  63. $nfm_box.hide();
  64. }
  65. // Ф-ии ajax-обновления
  66. var update = {
  67. // Лента
  68. feed: function(){
  69. $.getJSON(APP_URL + '/user/ajax/feedgrid/?isUnread=1&offset=0&limit=100&sortField=0&sortDir=0',
  70. function(result){
  71. $nfm_content.empty().html(result.body);
  72. $nfm_content.find("#gridTop").next("div")
  73. .empty()
  74. .css({'margin-bottom': "10px"})
  75. .append(
  76. $('<span class="cBlueButton">отметить все как прочитанное</span>')
  77. .click(function(){
  78. $.getJSON(APP_URL + '/user/ajax/feedmarkasread/',
  79. function(res){
  80. update.feed();
  81. });
  82. })
  83. );
  84. $nfm_content.find("#gridBottom").prev("div").empty();
  85. $("#nfm_content table.blueHeader.flex").css({'background-color': "#fff"});
  86. $("#nfm_content table.blueHeader.flex td")
  87. .css({ 'color': "#128", 'font-weight': "bold", 'padding': "0 10px", });
  88. $("#nfm_content table.blueHeader.flex a")
  89. .css({ 'color': "#128", 'text-decoration': "underline", 'font-weight': "bold", });
  90. if(result.total > 0){
  91. $("#nfm_content .frameBlock").hide();
  92. }
  93. $("#nfm_content .forumMessagesListMessageBody").hide();
  94. $("#nfm_content .fItem.forumMessagesListMessageVoteSwitch").closest("table").hide();
  95. $("#nfm_content .forumMessagesListMessage").each(function(mx, msg){
  96. var m_id = $(msg).attr("id").replace(/forumMessagesListMessage(\d+)/, "$1");
  97. if( window.myFollows ){
  98. window.myFollows.add_button(msg);
  99. }
  100. var $sh_button = $('<span class="cBlueButton" style="width: 60px; text-align: center;" m_id="'+m_id+'">Показать</span>')
  101. .click(function(){
  102. $(msg).closest("table").prev("div").toggle();
  103. var isVisible = $(msg).find(".forumMessagesListMessageBody").toggle().is(":visible");
  104. $(msg).find(".fItem.forumMessagesListMessageVoteSwitch").closest("table").toggle();
  105. $(this).html( ['Показать', 'Скрыть'][+isVisible] );
  106. });
  107. $(msg).find(".forumMessagesListMessageButtons table.cButtonsPanel").before($sh_button);
  108. });
  109. updateButton("feed", result.total);
  110. init_func();
  111. }
  112. );
  113. },
  114. // Уведомления
  115. notifies: function(){
  116. $.getJSON(APP_URL + '/user/ajax/notifiesinboxgrid/?offset=0&limit=100&sortField=1&sortDir=0',
  117. function(result){
  118. $nfm_content.empty().html(result.body);
  119. $("#nfm_content td.vaTop.taRight").parent().each(function(trx, tr){
  120. $(tr).after(
  121. $('<tr>').append( $mtd = $('<td class="vaTop" colspan="3">') )
  122. );
  123. $(tr).find("div[id$=ViewContainer]").detach().appendTo($mtd);
  124. $(tr).find(".userNotifiesInboxGridNotifyViewButton").closest("table")
  125. .detach()
  126. .appendTo( $(tr).find("td.vaTop.taRight") );
  127. });
  128. $("#nfm_content .userNotifiesInboxGridNotifyViewButton")
  129. .css({ width: "60px" })
  130. .html("Показать")
  131. .click(function(){
  132. var n_id = $(this).attr("id").replace(/userNotifiesInboxGridNotify(\d*?)ViewButton/, "$1"),
  133. $m_box = $("#userNotifiesInboxGridNotify" + n_id + "ViewContainer");
  134. if( $m_box.is(":visible") == true ){
  135. $m_box.hide();
  136. $(this).html("Показать");
  137. return;
  138. }
  139. $m_box.slideDown(200);
  140. $(this).html("Скрыть");
  141. }
  142. );
  143. $("#nfm_content .userNotifiesInboxGridNotifyMarkAsReadButton").hide().click(function(){
  144. var n_id = $(this).attr("id").replace(/userNotifiesInboxGridNotify(\d*?)MarkAsReadButton/, "$1");
  145. $.getJSON(APP_URL + '/user/ajax/markasreadnotify/?notifyId=' + n_id,
  146. function(res){
  147. update.notifies();
  148. });
  149. });
  150. $("#nfm_content .userNotifiesInboxGridNotifyDeleteButton").click(function(){
  151. var n_id = $(this).attr("id").replace(/userNotifiesInboxGridNotify(\d*?)DeleteButton/, "$1");
  152. $.getJSON(APP_URL + '/user/ajax/deletenotify/?notifyId=' + n_id,
  153. function(res){
  154. update.notifies();
  155. });
  156. });
  157. updateButton("notifies", result.total);
  158. init_func();
  159. }
  160. );
  161. },
  162. // Cообщения
  163. pm: function(){
  164. //
  165. },
  166. };
  167. // Главный цикл - модификация кнопок в панели.
  168. $(document).ready(function(){
  169. console.log('GA feed & notifies. Started.');
  170. $.each(bcapts, function(bname, bcaption){
  171. $btn[bname] = $(lUserPanel+' a[href*="glav.su/user/'+bname+'/"]')
  172. .attr("bhref", APP_URL+'/user/'+bname+'/')
  173. .attr("btag", bname)
  174. .attr("bcapt", bcaption)
  175. .attr("href", 'javascript: void(0);')
  176. .click(function(){
  177. var btag = $(this).attr("btag");
  178. if($nfm_box.is(":visible") == true){
  179. box_close();
  180. if( $nfm_box.bname == btag ){
  181. return;
  182. }
  183. }
  184. $("#nfm_title").empty().append(
  185. $('<a href="'+APP_URL+'/user/'+bname+'/" style="color: #fff;" target="blank">'+bname+'</a>')
  186. .mouseup(function(){
  187. box_close();
  188. })
  189. );
  190. $nfm_box.bname = btag;
  191. $nfm_content.empty();
  192. update[btag]();
  193. $nfm_box.css({left: 400}).slideDown(200);
  194. });
  195. });
  196. });
  197. // Недостающие функции работы с сообщениями на главной странице (спойлер, карма)
  198. var init_func = function(){return}; // пустышка для остальных страниц.
  199. if( location.href === APP_URL+'/forum/' ){
  200. // HTML форма для показа результатов голосования по карме
  201. var $vote_box = $('<div id="vote_box">')
  202. .css({ 'border': "1px solid #aaa", 'border-radius': "5px", 'width': '450px',
  203. 'height': '250px', 'background-color': "#fff", 'position': "absolute",
  204. 'box-shadow': "3px 3px 10px #555", 'overflow': "hidden", 'display': "none", })
  205. .append($('<div id="vote_header">')
  206. .css({ 'text-align': "right", 'padding': "2px", 'height': "20px", 'background-color': "#aaa",
  207. 'margin': "3px", 'border-radius': "3px 3px 0 0", })
  208. .append($vote_close = $('<a href="javascript:void(0);" id="vote_close" title="Закрыть">&times;</a>')
  209. .css({ 'width': "20px", 'height': "20px", 'border-radius': "3px",
  210. 'background-color': "transparent", 'text-align': "center",
  211. 'font-size': "20px", 'font-weight': "bold", 'text-decoration': "none",
  212. 'color': "#fff", 'display': "block", 'float': "right", })
  213. )
  214. .append($('<span id="vote_title">Экспертное голосование</span>')
  215. .css({ 'display': "block", 'width': "100%", 'text-align': "left", 'font-weight': "bold", })
  216. )
  217. )
  218. .append($('<div id="vote_scroller">')
  219. .css({ 'overflow-y': "auto", 'position': "absolute", 'bottom': "5px", 'top': "30px",
  220. 'right': "3px", 'left': "3px", 'background-color': "#fff", })
  221. .append($vote_content = $('<div id="vote_content">')
  222. .css({ 'color': "#000", 'height': "auto", 'padding': "5px", 'display': "block", })
  223. )
  224. )
  225. .appendTo( $(lUserPanel) );
  226. // Прибитие к кнопкам недостающих функций
  227. init_func = function(){
  228. // спойлер
  229. $(".cBlockSpoilerHeaderOff").click(function(){
  230. var bc = ['cBlockSpoilerHeaderOn', 'cBlockSpoilerHeaderOff'],
  231. isVisible = +( $(this).next("div").toggle().is(":visible") );
  232. $(this).removeClass(bc[isVisible]).addClass(bc[+(!isVisible)]);
  233. });
  234. // карма
  235. $("span[class^=forumMessagesListMessageVote]").click(function(){
  236. var match = $(this).attr("id").match(/forumMessagesListMessage(\d+)Vote(.+?)Button/),
  237. m_id = match[1], _this = this;
  238. if( match[2] === 'Info' ){
  239. $.get(APP_URL + '/forum/ajax/loadmessagevotehistory/', {
  240. messageId: m_id,
  241. }, function (res) {
  242. $vote_box.hide().detach();
  243. $vote_content.empty().html( (res.status)? res.info : 'Произошла ошибка при загрузке данных!' );
  244. $vote_box.appendTo($tb=$(_this).closest("table"))
  245. .css({ top: $tb.offset().top - window.scrollY + $nfm_scroller.scrollTop() - 317 })
  246. .show();
  247. }, 'json');
  248. }else{
  249. var sign = ({Positive: '+', Negative: '-'})[match[2]];
  250. $.post(APP_URL + '/forum/ajax/votemessage/', {
  251. messageId: m_id,
  252. sign: sign,
  253. csrftoken: CSRF_TOKEN,
  254. }, function (res) {
  255. if (res.status) {
  256. $('#forumMessagesListMessage'+m_id+'VoteNegativeButton').hide();
  257. $('#forumMessagesListMessage'+m_id+'VotePositiveButton').hide();
  258. $('#forumMessagesListMessage'+m_id+'VoteInfoButton').html(res.rating + ' / ' + res.votes);
  259. }
  260. }, 'json');
  261. }
  262. });
  263. $vote_close
  264. .hover(
  265. function(){ $(this).css({'background-color': "#e00"}); },
  266. function(){ $(this).css({'background-color': "transparent"}); }
  267. )
  268. .click(function(){
  269. $vote_box.hide();
  270. })
  271. };
  272. }

QingJ © 2025

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