Create instant reverse image search links for image posts
当前为
// ==UserScript==
// @name Reddit Image Search Add-on
// @namespace https://gf.qytechs.cn/en/users/76021-dalimcodes
// @version 0.1
// @description Create instant reverse image search links for image posts
// @author DaLimCodes
// @match https://*.reddit.com/*
// @require https://code.jquery.com/jquery-3.3.1.min.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_listValues
// @grant GM_deleteValue
// ==/UserScript==
/* for non-RES user, to be integrated to current RES-friendly code
$(document).ready(function(){
var entry = $(".expando");
for (i=0; i<entry.length; i++){
var obj = $(entry[i]);
console.log(obj);
if(obj.attr("data-cachedhtml") !== undefined){
var cachedhtml = $($.parseHTML(obj.attr("data-cachedhtml").trim()));
var link = cachedhtml.find("a.may-blank").attr("href");
if (link !== undefined){
obj.closest("div.entry").find("ul.buttons").append(`<li class="reverse-search-button"><a style="color:darkgreen;" href="https://saucenao.com/search.php?url=${link}" target="_blank">SauceNAO</a></li>`);
console.log(link);
}
}
}
});
*/
const imageSupported = /\.(gif|jpe?g|png)/i;
const debug = true;
$(document).ready(function(){
if (debug){
console.log("Reddit RIS debug in action!");
}
var things = $("div.thing.link");
for (i=0; i<things.length; i++){
var obj = $(things[i]);
var link = obj.attr("data-url");
if (link.match(imageSupported)){
// Check if it's a three or four letter image extension
if(link.charAt(link.regexLastIndexOf(imageSupported)+4).match(/[a-zA-Z]/)){
link = link.substr(0,link.regexLastIndexOf(imageSupported)+5);
} else {
link = link.substr(0,link.regexLastIndexOf(imageSupported)+4);
}
obj.find("ul.buttons").append(`<li class="reverse-search-button-saucenao"><a style="color:green;text-decoration: underline;" href="https://saucenao.com/search.php?url=${link}" target="_blank">SauceNAO</a></li>`);
obj.find("ul.buttons").append(`<li class="reverse-search-button-gooogle"><a style="color:green;text-decoration: underline;" href="https://images.google.com/searchbyimage?image_url=${link}" target="_blank">Google</a></li>`);
if (debug){
console.log("Image link:", link);
}
} else {
if (debug){
console.log("Non-image link:", link);
}
}
}
});
// Credit to Jason Bunting (https://stackoverflow.com/questions/273789/is-there-a-version-of-javascripts-string-indexof-that-allows-for-regular-expr)
String.prototype.regexIndexOf = function(regex, startpos) {
var indexOf = this.substring(startpos || 0).search(regex);
return (indexOf >= 0) ? (indexOf + (startpos || 0)) : indexOf;
};
String.prototype.regexLastIndexOf = function(regex, startpos) {
regex = (regex.global) ? regex : new RegExp(regex.source, "g" + (regex.ignoreCase ? "i" : "") + (regex.multiLine ? "m" : ""));
if(typeof (startpos) == "undefined") {
startpos = this.length;
} else if(startpos < 0) {
startpos = 0;
}
var stringToWorkWith = this.substring(0, startpos + 1);
var lastIndexOf = -1;
var nextStop = 0;
while((result = regex.exec(stringToWorkWith)) != null) {
lastIndexOf = result.index;
regex.lastIndex = ++nextStop;
}
return lastIndexOf;
};
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址