shujo / amz-img-detector

// ==UserScript==
// @name         amz-img-detector
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  image detector in Amazon
// @author       Josh
// @match        https://www.amazon.com/gp/offer-listing/*
// @grant        GM_notification
// @grant        GM_addStyle
// @run-at       document-end
// @require      http://code.jquery.com/jquery-3.3.1.min.js
// @license      MIT
// ==/UserScript==
(function() {
    'use strict';
    let img = $('#olpProductImage > a > img').attr('src');
    if(img.indexOf('no-img') > -1){
       errorIcon();
       console.log('image not found');
    }else{
      successIcon();
      console.log('image found');
    }
})();


function errorIcon(){
    var favicon_link_html = document.createElement('link');
    favicon_link_html.rel = 'icon';
    favicon_link_html.href = 'https://img.icons8.com/cute-clipart/64/000000/error.png';
    favicon_link_html.type = 'image/png';
    try {
        document.getElementsByTagName('head')[0].appendChild( favicon_link_html );
        $('title').text('Image Not Found');
    }
    catch(e) { }
}
function successIcon(){
    var favicon_link_html = document.createElement('link');
    favicon_link_html.rel = 'icon';
    favicon_link_html.href = 'https://img.icons8.com/cute-clipart/64/000000/approval.png';
    favicon_link_html.type = 'image/png';
    try {
        document.getElementsByTagName('head')[0].appendChild( favicon_link_html );
        $('title').text('Image Found');
    }
    catch(e) { }
}