Greasy Fork is available in English.
On Oct 12, 2016, Amazon added a bunch of useless garbage variables to all the HIT links on MTurk search results pages, making your browser history no longer able to change the link color of HITs you've already visited. This script removes the garbage from those links so your browser history can work properly again. And if you put it first in your userscript execution order, it should also fix some other scripts that were affected by this garbage.
当前为
// ==UserScript==
// @name CH MTurk HIT Link Cleanup
// @description On Oct 12, 2016, Amazon added a bunch of useless garbage variables to all the HIT links on MTurk search results pages, making your browser history no longer able to change the link color of HITs you've already visited. This script removes the garbage from those links so your browser history can work properly again. And if you put it first in your userscript execution order, it should also fix some other scripts that were affected by this garbage.
// @version 1.0c
// @author clickhappier
// @namespace clickhappier
// @include https://www.mturk.com/mturk/*
// @require http://code.jquery.com/jquery-latest.min.js
// @grant GM_log
// ==/UserScript==
// get URL variable - adapted from http://css-tricks.com/snippets/javascript/get-url-variables/ to be universal vs window.location-only
function getUrlVariable(url, variable)
{
var query = url.split('?');
var vars = query[1].split("&");
for ( var i=0; i<vars.length; i++ )
{
var pair = vars[i].split("=");
if ( pair[0] == variable )
{ return pair[1]; }
}
return(false);
}
// set URL variable - from http://stackoverflow.com/questions/5999118/add-or-update-query-string-parameter/15023688#15023688
function setUrlVariable(uri, key, value) {
var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)", "i");
if (uri.match(re))
{
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else
{
var hash = '';
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if( uri.indexOf('#') !== -1 )
{
hash = uri.replace(/.*#/, '#');
uri = uri.replace(/#.*/, '');
}
return uri + separator + key + "=" + value + hash;
}
}
$('a[href*="/mturk/preview"]').each(function()
{
var oldLinkUrl = $(this).attr('href');
var newLinkUrl = "";
var groupIdValue = getUrlVariable(oldLinkUrl, "groupId");
// build cleaned HIT links
if ( oldLinkUrl.indexOf("/preview?") >= 0 )
{
if ( oldLinkUrl.indexOf("https:") >= 0 ) // if originally was a full link
{ newLinkUrl = setUrlVariable("https://www.mturk.com/mturk/preview", 'groupId', groupIdValue); }
else // if originally was a relative link
{ newLinkUrl = setUrlVariable("/mturk/preview", 'groupId', groupIdValue); }
}
else if ( oldLinkUrl.indexOf("/previewandaccept?") >= 0 )
{
if ( oldLinkUrl.indexOf("https:") >= 0 ) // if originally was a full link
{ newLinkUrl = setUrlVariable("https://www.mturk.com/mturk/previewandaccept", 'groupId', groupIdValue); }
else // if originally was a relative link
{ newLinkUrl = setUrlVariable("/mturk/previewandaccept", 'groupId', groupIdValue); }
}
else // just in case
{ newLinkUrl = oldLinkUrl; }
// apply completed url
$(this).attr('href', newLinkUrl);
});