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.

当前为 2014-09-01 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name          gathering.tweakers.net - Add Topic Bookmark
// @homepageURL   https://github.com/sand3r/tampermonkey-scripts/tree/master/gathering_of_tweakers
// @namespace     gathering.tweakers.net
// @version       0.03
// @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.
// @match         *://gathering.tweakers.net/forum/list_message*
// @include       http://gathering.tweakers.net
// @require       http://code.jquery.com/jquery-latest.js 
// @author        Sander Thalen
// ==/UserScript==

jQuery(document).ready(function() {

  (function(_$) {

    var bookMarkButtons = _$("a[href^='http://gathering.tweakers.net/forum/insert_bookmark/']");

    bookMarkButtons.each(function(i, object) {
      var buttons = _$(object);

      // Add event handler
      buttons.on('click', function(ev) {
        ev.preventDefault();
        
        var target = _$(ev.currentTarget);

        // Get required values
        var author        = target.parents('.message').find('.username a')[0].innerText,
            topicName     = _$('h1')[0].innerText,
            name          = author + ' in ' + '"' + topicName + '"',
            folder        = '11',
            reactId       = _$('[name="data[reactid]"]').val(),
            action        = 'insert_bookmark',
            messageId     = target.parents('.message').prev('a').attr('name'),
            topicId       = _$('[data-topicid]').attr('data-topicid'),
            httpReferrer  = window.location.href,
            button		  = target;
        
        // Make call
        bookMarkAsync(button, name, folder, reactId, action, messageId, topicId, httpReferrer);
        
      });

    });

    function bookMarkAsync(button, name, folder, reactId, action, messageId, topicId, httpReferrer) {
      
      _$.ajax({
        url: 'http://gathering.tweakers.net/forum',
        type: 'POST',
        data: {
          'data[name]': name,
          'data[folder]': folder,
          'data[reactid]': reactId,
          'action': action,
          'data[messageid]': messageId,
          'data[topicid]': topicId,
          'data[http_referrer]': httpReferrer
        }
      })
      .success(function() {
        
        button.css({
          'color':				'rgb(40, 160, 40)',
          'font-weight': 		'bold'
        });
        
      });
  
    }

  })(jQuery);
});