Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MisterDuval/24f08c932e4f308d42315f1fb4277535 to your computer and use it in GitHub Desktop.
Save MisterDuval/24f08c932e4f308d42315f1fb4277535 to your computer and use it in GitHub Desktop.
user.js
// ==UserScript==
// @name ReviewMeta Amazon Search
// @namespace http://tampermonkey.net/
// @version 0.1.2
// @description Modify star ratings on Amazon pages based on ReviewMeta scores
// @author bhughes339
// @include https://*.amazon.tld/*
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
/* Color legend:
Green - Pass (good)
Orange - Warn (iffy)
Red - Fail (bad)
Grey - Not yet analyzed by ReviewMeta */
(function() {
'use strict';
function modStars(asin, ele) {
$.getJSON('https://reviewmeta.com/api/amazon/' + asin, function(data) {
switch (data.s_overall) {
case "1":
ele.attr('style', 'filter:hue-rotate(40deg)');
break;
case "2":
ele.attr('style', 'filter:hue-rotate(340deg)');
break;
case "3":
ele.attr('style', 'filter:hue-rotate(315deg) saturate(500%)');
break;
default:
ele.attr('style', 'filter:grayscale(100%)');
ele.attr('onclick', "window.open('" + data.href + "');");
break;
}
});
}
var url = window.location.href;
var asinMatch = url.match(/\/(B[\dA-Z]{9}|\d{9}(?:X|\d))/); // https://stackoverflow.com/questions/2123131/determine-if-10-digit-string-is-valid-amazon-asin
var srch = (asinMatch) ? 'span#acrPopover' : 'span[name]';
$(srch).each(function(index) {
var asin = (asinMatch) ? asinMatch[1] : $(this).attr('name');
var $self = $(this);
modStars(asin, $self);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment