netheoc / No Resize Limited for "Open Image in..."

// ==UserScript==
// @name         No Resize Limited for "Open Image in..."
// @version      1.14
// @description  PrTimes, Twitter, realsound.jp, ameba blog, cloudfront/amazon aws uploads, lisani, partial natalie, stayluck, seigura/gallery server, lnk.to, news.yahoo.co.jp
// @author       netheoc
// @license      MIT
// @grant        none
// @match        http*://prtimes.jp/i/*
// @match        http*://pbs.twimg.com/media*
// @match        *.cloudfront.net/wp-content/uploads/*
// @match        http*://realsound.jp/wp-content/uploads*
// @match        http*://stat.ameba.jp/user_images*
// @match        *.amazonaws.com/*
// @match        *.lisani.jp/admin/wp-content/uploads/*
// @match        http*://ogre.natalie.mu/media/*
// @match        http*://stay-luck.com/wp-content/*
// @match        http*://seigura.com/*
// @match        http*://seigura.secureserv.jp/*
// @match        http*://linkstorage.linkfire.com/medialinks/images/*
// @match        http*://newsatcl-pctr.c.yimg.jp/*
// ==/UserScript==


//TODO: reorder desc acc to number of checks at if

var tR = ""; //to replace
var rW = ""; //replace with
var loO = document.location; //location object
var oU = loO.toString(); //old URL
var nU = ""; //new URL
var aA; //extra var for generic use
var bB;

//error reporting
window.onerror = function (msgStr, srcStr, lineNum, colNum, errObj){
    console.log(msgStr, srcStr, errObj);
};
window.addEventListener('error', function(errEv) {
    console.log(errEv.toString());
});

//
//prtimes.jp
if (oU.includes("prtimes.jp/i") && oU.includes("resize")){
    tR = "resize";
    rW = "orig";
    repURL(oU, tR, rW);
//    nU = oU.replace(tR, rW);
//    document.location.replace(nU);
    //
    //twitter
} else if (oU.includes("pbs.twimg.com/media")){
    //format=jpg&name...
    if (oU.includes("&name=small")){
        tR = loO.search;
        rW = tR.slice(0, tR.indexOf("&name"));
        repURL(oU, tR, rW);
    };
    //1.09 change to name=small only
    /*.jpg:large etc; regex for possible png
    if (oU.search(/\.[a-z]{3}:[a-z]{5,}/g)>0){ //assumes "large" or "small" only
        aA = oU.search(/\.[a-z]{3}:[a-z]{5,}/g) + 4; //need to acc for "jpeg"?
        nU = oU.slice(0, aA);
        document.location.replace(nU);
    };
    */
    //
    // natalie
} else if (oU.includes("ogre.natalie.mu") && (loO.search != "")){
    tR = loO.search;
    rW = "";
    repURL(oU, tR, rW);
    //
    // realsound, lisani
} else if ((oU.includes("realsound.jp") || oU.includes("lisani.jp")) && (oU.search(/-\d{3,4}x\d{3,4}\./g)>-1)){
    aA = oU.search(/-\d{3,4}x\d{3,4}\./g);
    bB = oU.match(/-\d{3,4}x\d{3,4}\./g).toString().length - 1;
    nU = oU.slice(0, aA) + oU.slice(aA+bB);
    document.location.replace(nU);
    //
    // stayluck
} else if (oU.includes("stay-luck.com") && (oU.search(/-\d{3,4}x\d{3,4}\./g)>-1)){
    aA = oU.search(/-\d{3,4}x\d{3,4}\./g);
    bB = oU.match(/-\d{3,4}x\d{3,4}\./g).toString().length - 1;
    nU = oU.slice(0, aA) + oU.slice(aA+bB);
    document.location.replace(nU);
    //
    // cloudfront and amazonaws
    // regex looks for "-###(#) x ###(#)." 3-4 # per, no space
} else if ((oU.includes("cloudfront.net") || oU.includes("amazonaws.com")) && (oU.search(/-\d{3,4}x\d{3,4}\./g)>-1)){
    aA = oU.search(/-\d{3,4}x\d{3,4}\./g);
    bB = oU.match(/-\d{3,4}x\d{3,4}\./g).toString().length - 1;
    nU = oU.slice(0, aA) + oU.slice(aA+bB);
    document.location.replace(nU);
    //
    //lnk.to // copy of cloudfront regex
} else if ((oU.includes("linkstorage.linkfire.com")) && (oU.search(/-\d{3,4}x\d{3,4}\./g)>-1)){
    aA = oU.search(/-\d{3,4}x\d{3,4}\./g);
    bB = oU.match(/-\d{3,4}x\d{3,4}\./g).toString().length - 1;
    nU = oU.slice(0, aA) + oU.slice(aA+bB);
    document.location.replace(nU);
    //
    //seigura -scaled (need to account for added stuff after scaled until extension name .jpg or jpeg) and dimension regex
} else if (oU.includes("seigura.com")){
    if (oU.includes("-scaled")){
    aA = oU.indexOf("-scaled");
    bB = oU.indexOf(".jp");
    nU = oU.slice(0, aA) + oU.slice(bB, oU.length);
    document.location.replace(nU);
    };
    if (oU.search(/-\d{3,4}x\d{3,4}\./g)>-1){
    aA = oU.search(/-\d{3,4}x\d{3,4}\./g);
    bB = oU.match(/-\d{3,4}x\d{3,4}\./g).toString().length - 1;
    nU = oU.slice(0, aA) + oU.slice(aA+bB);
    document.location.replace(nU);
    };
    //
    //seigura gallery server: remove "sample"
    //TODO: add support for jp*g
} else if (oU.includes("seigura.secureserv.jp")){
    if (oU.includes("_sample")){
    aA = oU.indexOf("_sample");
    bB = oU.indexOf(".jpg");
    nU = oU.slice(0, aA) + oU.slice(bB, oU.length);
    document.location.replace(nU);
    };
    //
    //ameba blog
} else if (oU.includes("stat.ameba") && (loO.search.length > 2)){
    tR = loO.search;
    rW = "";
    repURL(oU, tR, rW);
    //
    //news.yahoo.co.jp
} else if (oU.includes("newsatcl-pctr.c.yimg.jp") && (loO.search != "")){
    tR = loO.search;
    rW = "";
    repURL(oU, tR, rW);
} // else {return;};

//replace URL
function repURL(o, t, r){
    var n = o.replace(t, r);
    document.location.replace(n);
//    alert("no resize script replaced url"); //alert pops up before refresh
    return;
};

/* mantan does not always go to size10: should look into history states to implement
natalie.mu: remove s for some, diff approach for others
   ogre= remove search
animeanime uses diff hashes?
okmusic??
*/