GoT: Add Topic Bookmark

Makes the bookmark button for a post work asynchronously. Click Bookmark and wait for it to turn Green.

As of 2014-08-29. See the latest version.

  1. // ==UserScript==
  2. // @name GoT: Add Topic Bookmark
  3. // @namespace gathering.tweakers.net
  4. // @version 0.02
  5. // @description Makes the bookmark button for a post work asynchronously. Click Bookmark and wait for it to turn Green.
  6. // @match *://gathering.tweakers.net/forum/list_message*
  7. // @include http://gathering.tweakers.net
  8. // @require http://code.jquery.com/jquery-latest.js
  9. // @author Sander Thalen
  10. // ==/UserScript==
  11.  
  12. jQuery(document).ready(function() {
  13.  
  14. (function(_$) {
  15.  
  16. var bookMarkButtons = _$("a[href^='http://gathering.tweakers.net/forum/insert_bookmark/']");
  17.  
  18. bookMarkButtons.each(function(i, object) {
  19. var buttons = _$(object);
  20.  
  21. // Add event handler
  22. buttons.on('click', function(ev) {
  23. ev.preventDefault();
  24. var target = _$(ev.currentTarget);
  25.  
  26. // Get required values
  27. var author = target.parents('.message').find('.username a')[0].innerText,
  28. topicName = _$('h1')[0].innerText,
  29. name = author + ' in ' + '"' + topicName + '"',
  30. folder = '11',
  31. reactId = _$('[name="data[reactid]"]').val(),
  32. action = 'insert_bookmark',
  33. messageId = target.parents('.message').prev('a').attr('name'),
  34. topicId = _$('[data-topicid]').attr('data-topicid'),
  35. httpReferrer = window.location.href,
  36. button = target;
  37. // Make call
  38. bookMarkAsync(button, name, folder, reactId, action, messageId, topicId, httpReferrer);
  39. });
  40.  
  41. });
  42.  
  43. function bookMarkAsync(button, name, folder, reactId, action, messageId, topicId, httpReferrer) {
  44. _$.ajax({
  45. url: 'http://gathering.tweakers.net/forum',
  46. type: 'POST',
  47. data: {
  48. 'data[name]': name,
  49. 'data[folder]': folder,
  50. 'data[reactid]': reactId,
  51. 'action': action,
  52. 'data[messageid]': messageId,
  53. 'data[topicid]': topicId,
  54. 'data[http_referrer]': httpReferrer
  55. }
  56. })
  57. .success(function() {
  58. button.css({
  59. 'color': 'rgb(40, 160, 40)',
  60. 'font-weight': 'bold'
  61. });
  62. });
  63. }
  64.  
  65. })(jQuery);
  66. });