userscripts/amaz.giveaway.user.js

44 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2017-09-28 10:30:53 -05:00
// ==UserScript==
// @name Official Amazon Giveaway Listing Visited Remover
// @namespace danielrayjones
// @description Allow removal of visited links on Amazon Giveaway Listing
2017-09-28 10:33:25 -05:00
// @include https://smile.amazon.com/ga/giveaways*
// @include https://www.amazon.com/ga/giveaways*
2017-10-18 07:05:23 -05:00
// @version 1.6
2017-09-28 10:30:53 -05:00
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// ==/UserScript==
var checked = false;
2017-09-28 11:56:42 -05:00
var getSmallUrl = function(fullUrl) {
return fullUrl.split('?')[0];
};
2017-09-28 10:30:53 -05:00
var hideOne = function(el) {
$(el).parents('div.a-spacing-base').css('display', checked ? 'none' : 'block');
2017-09-28 10:30:53 -05:00
};
var hideVisited = function(evt) {
checked = $(this).prop('checked');
var $links = $('.landingPageSpacings a[href*="amazon.com/ga"]');
2017-09-28 10:30:53 -05:00
$links.each(function() {
2017-09-28 11:56:42 -05:00
var href = getSmallUrl($(this).attr('href'));
2017-09-28 10:30:53 -05:00
if (localStorage.getItem(href)) {
hideOne(this);
}
});
};
$(document).ready(function() {
$('.landingPageSpacings').on('click', 'a[href*="amazon.com/ga"]', function(evt) {
2017-09-28 10:30:53 -05:00
2017-09-28 11:56:42 -05:00
var href = getSmallUrl($(this).attr('href'));
2017-09-28 10:30:53 -05:00
localStorage[href] = "visited";
hideOne(this);
});
$('h1:contains("Giveaways")').after('<label><input type="checkbox" id="hide_visited"/> Visited</label>');
2017-09-28 10:30:53 -05:00
$('#hide_visited').on('click', hideVisited);
});