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.
当前为
// ==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);
});