Greasy Fork is available in English.

gathering.tweakers.net - Add Topic Bookmark

Makes the bookmark button for a post on the GoT Forum (gathering.tweakers.net) work asynchronously. Click Bookmark and wait for it to turn Green.

Verze ze dne 14. 08. 2015. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name gathering.tweakers.net - Add Topic Bookmark
  3. // @homepageURL https://github.com/sand3r/tampermonkey-scripts/tree/master/gathering_of_tweakers
  4. // @namespace gathering.tweakers.net
  5. // @version 0.051
  6. // @description Makes the bookmark button for a post on the GoT Forum (gathering.tweakers.net) work asynchronously. Click Bookmark and wait for it to turn Green.
  7. // @match *://gathering.tweakers.net/forum/list_message*
  8. // @include http://gathering.tweakers.net
  9. // @require http://code.jquery.com/jquery-latest.js
  10. // @author Sander Thalen
  11. // ==/UserScript==
  12.  
  13. jQuery(document).ready(function() {
  14.  
  15. var bookmarkManager = (function(_$) {
  16. var bookMarkButtons = _$("a[href^='http://gathering.tweakers.net/forum/insert_bookmark/']");
  17.  
  18. function bindBookmarkButtons() {
  19.  
  20. bookMarkButtons.each(function(i, object) {
  21. var buttons = _$(object);
  22. // Add event handler
  23. buttons.on('click', function(ev) {
  24. ev.preventDefault();
  25. var target = _$(ev.currentTarget);
  26.  
  27. // Get required values
  28. var author = target.parents('.message').find('.username a')[0].innerText,
  29. topicName = _$('h1')[0].innerText,
  30. name = author + ' in ' + '"' + topicName + '"',
  31. folder = '11',
  32. reactId = _$('[name="data[reactid]"]').val(),
  33. action = 'insert_bookmark',
  34. messageId = target.parents('.message').prev('a').attr('name'),
  35. topicId = _$('[data-topicid]').attr('data-topicid'),
  36. httpReferrer = window.location.href,
  37. button = target;
  38.  
  39. // Make call
  40. bookMarkAsync(button, name, folder, reactId, action, messageId, topicId, httpReferrer);
  41. });
  42. });
  43.  
  44. }
  45.  
  46. function markButton(button) {
  47.  
  48. // Change color on button
  49. button.prepend('<img src="http://tweakimg.net/g/icons/checkmark-green.png" class="js_tm_bookmarked_state" /> ');
  50.  
  51. if(!button.hasClass('js_tm_bookmark_button')) {
  52. button.addClass('js_tm_bookmark_button');
  53. }
  54.  
  55. button.css({
  56. 'color': 'rgb(119, 164, 0)',
  57. 'font-weight': 'bold'
  58. });
  59.  
  60. }
  61.  
  62. function unmarkButton() {
  63.  
  64. _$('.js_tm_bookmarked_state').remove();
  65. _$('.js_tm_bookmark_button').removeAttr('style').empty().text('Bookmark');
  66.  
  67. }
  68.  
  69. function bookMarkAsync(button, name, folder, reactId, action, messageId, topicId, httpReferrer) {
  70. _$.ajax({
  71. url: 'http://gathering.tweakers.net/forum',
  72. type: 'POST',
  73. data: {
  74. 'data[name]' : name,
  75. 'data[folder]' : folder,
  76. 'data[reactid]' : reactId,
  77. 'action' : action,
  78. 'data[messageid]' : messageId,
  79. 'data[topicid]' : topicId,
  80. 'data[http_referrer]' : httpReferrer
  81. }
  82. })
  83. .success(function() {
  84. unmarkButton();
  85. markButton(button);
  86. });
  87. }
  88.  
  89. return {
  90. bindBookmarkButtons: bindBookmarkButtons
  91. }
  92.  
  93. })(jQuery);
  94.  
  95. bookmarkManager.bindBookmarkButtons();
  96.  
  97. });