userscripts/amaz.giveaway.user.js

61 lines
1.7 KiB
JavaScript
Raw 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-23 07:59:12 -05:00
// @version 1.7.2
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-10-20 12:45:10 -05:00
var regex_hide;
2017-09-28 10:30:53 -05:00
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
2017-10-20 12:45:10 -05:00
var hide = regex_hide ? new RegExp(regex_hide, 'i') : null;
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);
}
2017-10-20 12:45:10 -05:00
2017-10-23 07:59:12 -05:00
var title= $(this).parent('.a-row').siblings('.ellipsis-1-line').text();
if (hide && title && hide.test(title)) {
2017-10-20 12:45:10 -05:00
hideOne(this);
}
2017-09-28 10:30:53 -05:00
});
};
$(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);
});
2017-10-20 12:45:10 -05:00
regex_hide = localStorage.getItem('regex_hide') || '';
$('h1:contains("Giveaways")')
.after('<label><input type="checkbox" id="hide_visited"/> Visited</label>')
.after(`<input id="hide_regex" value="${regex_hide}"/>`);
2017-10-20 12:45:10 -05:00
2017-09-28 10:30:53 -05:00
$('#hide_visited').on('click', hideVisited);
2017-10-20 12:45:10 -05:00
$('#hide_regex').on('change', function() {
regex_hide = $(this).val();
localStorage.regex_hide = regex_hide;
});
2017-09-28 10:30:53 -05:00
});