Created
May 10, 2019 01:30
-
-
Save jaideejung007/5112511dd8b8e7d2ce9e17ba3e34c771 to your computer and use it in GitHub Desktop.
Tampermonkey - SiamBit Zoom Screen Shot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name SiamBit Zoom Screen Shot | |
// @namespace http://tampermonkey.net/ | |
// @version 0.23 | |
// @description Show screen shot when mouse hover icon camera or title name | |
// @author น้องแมว | |
// @match https://www.siambit.me/* | |
// @require https://code.jquery.com/jquery-1.12.4.min.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.min.js | |
// @grant GM_addStyle | |
// @grant GM_xmlhttpRequest | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @grant GM_deleteValue | |
// @updateURL https://gist.githubusercontent.com/akoneko/92613cd3f6a9aa221ccb5af5df46b8aa/raw/a308ddbfa33421838aad980273e74c7f5b8b9bf6/Tampermonkey-SiamBitZoomScreenShot.js | |
// @downloadURL https://gist.githubusercontent.com/akoneko/92613cd3f6a9aa221ccb5af5df46b8aa/raw/a308ddbfa33421838aad980273e74c7f5b8b9bf6/Tampermonkey-SiamBitZoomScreenShot.js | |
// ==/UserScript== | |
// lib imagepreview | |
!function(a) { | |
"use strict"; | |
var debug = false; | |
function extractHostname(url) { | |
var hostname; | |
if (url.indexOf("//") > -1) { | |
hostname = url.split('/')[2]; | |
} | |
else { | |
hostname = url.split('/')[0]; | |
} | |
hostname = hostname.split(':')[0]; | |
hostname = hostname.split('?')[0]; | |
return hostname; | |
} | |
function timestamp(){ | |
return (Date.now() / 1000 | 0); | |
} | |
function cacheGenKey(url){ | |
return 'cache_real_url_' + md5(url); | |
} | |
function cacheGet(key,valueDefault){ | |
let cache = GM_getValue(key, null); | |
if(cache){ | |
cache = JSON.parse(cache); | |
cache = a.extend({ | |
val: null, | |
timeout: timestamp(), | |
},cache); | |
if(cache.timeout > timestamp()){ | |
return cache.val; | |
}else{ | |
GM_deleteValue(key) | |
} | |
} | |
return valueDefault; | |
} | |
function cacheSet(key,val,minute){ | |
let cache = { | |
val: val, | |
timeout: timestamp() + (minute*60), | |
}; | |
GM_setValue(key,JSON.stringify(cache)); | |
} | |
function cacheHas(key){ | |
return cacheGet(key,null) !== null; | |
} | |
async function findRealUrlImageFromUrlWebsite(webUrl,mode,argument,callback){ | |
return await new Promise(resolve => { | |
GM_xmlhttpRequest ( { | |
method: "GET", | |
url: webUrl, | |
synchronous: true, | |
onload: function (response) { | |
let responseHTML = new DOMParser().parseFromString(response.responseText, "text/html"); | |
let data; | |
if(mode ==='meta'){ | |
data = a("meta[property='" + argument + "']",responseHTML).attr("content"); | |
}else if(mode === 'selectors.src'){ | |
data = a(argument,responseHTML).first().attr("src"); | |
} | |
if(callback){ | |
callback(response) | |
} | |
resolve(data); | |
} | |
}); | |
}) | |
} | |
async function getRealUrlImage(url){ | |
let key = cacheGenKey(url); | |
let cache = cacheGet(key,null); | |
if(cache){ | |
if(debug) console.log('use cache ' + cache) | |
return cache | |
} | |
if(url.match(/\.(jpeg|jpg|gif|png)$/) != null | |
&& url.indexOf('img.best-story.net/viewer') === -1 | |
){ | |
return url | |
} | |
let domain = extractHostname(url); | |
switch(domain) { | |
case "postto.me": | |
url = await findRealUrlImageFromUrlWebsite(url,'selectors.src','div.image_view img') | |
break; | |
case "www.imgbb.me" : | |
case "imgbb.me" : | |
case "www.picz.in.th" : | |
case "picz.in.th" : | |
case "www.imgtrue.com" : | |
case "imgtrue.com" : | |
case "imdb.com" : | |
case "www.imdb.com" : | |
url = await findRealUrlImageFromUrlWebsite(url,'meta','og:image') | |
break; | |
case "img.best-story.net" : | |
url = url.replace('viewer.php?file=','files/'); | |
break; | |
case "imgur.com" : | |
var _url = url.replace("https://","").replace("http://","") | |
if(_url.startsWith("imgur.com/a/")){ | |
url = await findRealUrlImageFromUrlWebsite(url,'meta','twitter:image') | |
} | |
break; | |
} | |
return url; | |
} | |
function runtimeNow() { | |
return new Date().getTime(); | |
} | |
window.statusElementLoadingShow = false; | |
window.anarchytipRuntime = runtimeNow(); | |
window.anarchytipRuntimeHover = null; | |
a.fn.anarchytip = function(b) { | |
var c = a.extend({ | |
xOffset: 10, | |
yOffset: 30, | |
yOffsetFix: 0, | |
yOffsetPreLoadFix: 0, | |
previewTop: 0, | |
previewLeft: 0, | |
elePreview : a('<p>',{id:'preview'}), | |
eleImage : a('<img/>',{alt:'Image preview'}), | |
runtime : runtimeNow(), | |
loading : 'https://i.imgur.com/3bhmEVs.gif', | |
eleLoadingShow : false, | |
}, b); | |
a("#preview").remove() | |
a("body").append(c.elePreview.append(c.eleImage)) | |
var $showPreview = function (t,l){ | |
if(debug) console.log('show',window.anarchytipRuntime) | |
c.elePreview.css({ | |
top: t + "px", | |
left: l + "px" | |
}).show(); | |
// } | |
if(debug) console.log(c.eleImage.attr('src')) | |
} | |
c.eleImage.on('load', function() { | |
if(debug) console.log('load',window.anarchytipRuntime) | |
let top = c.previewTop; | |
c.yOffsetPreLoadFix = 0; | |
if(debug) console.log('load fail. ',this.src) | |
if(this.src !== c.loading && this.src){ | |
top = top + c.yOffsetFix; | |
c.yOffsetPreLoadFix = c.yOffsetFix; | |
let imageSrc = a(this).attr('data-base-url'); | |
if(!cacheHas(cacheGenKey(imageSrc))){ | |
if(debug) console.log('write cache') | |
cacheSet(cacheGenKey(imageSrc),this.src,10) | |
} | |
if(debug) console.log(this.src) | |
$showPreview(top,c.previewLeft); | |
}else{ | |
c.elePreview.hide() | |
} | |
if(debug) console.log(1) | |
}).on('error', function() { | |
c.yOffsetFix = 0; | |
c.yOffsetPreLoadFix = 0; | |
c.elePreview.css({ | |
top: c.previewTop + "px", | |
left: c.previewLeft + "px", | |
background : '#333', | |
}) | |
if(debug) console.log(2) | |
}) | |
return this.each(function() { | |
var b = a(this); | |
var imageHeight = Math.ceil(window.innerHeight * 0.6); | |
var imageSrc = b.attr('data-preview'); | |
var offset = a(this).offset(); | |
if(debug) console.log('loop') | |
b.hover(async function(b) { | |
if(window.anarchytipRuntimeHover == b){ | |
return; | |
}else{ | |
window.anarchytipRuntimeHover = b | |
} | |
if(debug) console.log(3) | |
c.eleLoadingShow = true; | |
window.statusElementLoadingShow = true; | |
c.yOffsetFix = 0; | |
c.previewTop = b.pageY - c.xOffset; | |
c.previewLeft = b.pageX + c.yOffset; | |
c.yOffsetPreLoadFix = 0; | |
$showPreview(c.previewTop,c.previewLeft); | |
c.yOffsetFix = (window.innerHeight - b.clientY - imageHeight); | |
c.yOffsetFix = c.yOffsetFix < 0 ? (c.yOffsetFix - 50): 0; | |
window.anarchytipRuntime = runtimeNow(); | |
let running = window.anarchytipRuntime; | |
let imageRealUrl = await getRealUrlImage(imageSrc); | |
if(running < window.anarchytipRuntime){ | |
return; | |
} | |
c.yOffsetPreLoadFix = 0; | |
c.eleImage.css({'max-height':imageHeight+'px'}).attr("src", imageRealUrl).attr('data-base-url',imageSrc); | |
if(debug) console.log(4) | |
}, function() { | |
window.anarchytipRuntimeHover = null; | |
window.statusElementLoadingShow = false; | |
window.anarchytipRuntime = runtimeNow(); | |
c.eleLoadingShow = false; | |
if(debug) console.log(5) | |
if(c.elePreview){ | |
c.elePreview.hide() | |
//c.eleImage.removeAttr('src'); | |
c.eleImage.attr('src',c.loading); | |
c.previewTop = b.pageY - c.xOffset; | |
c.yOffsetPreLoadFix = 0; | |
c.elePreview.css({ | |
background : '#fff', | |
display:'none', | |
}) | |
if(debug) console.log(6) | |
} | |
if(debug) console.log('hide',window.anarchytipRuntime) | |
}) | |
b.mousemove(function(b) { | |
if(c.elePreview && c.eleLoadingShow){ | |
c.elePreview.css("top",b.pageY - c.xOffset + c.yOffsetPreLoadFix +"px").css("left",b.pageX + c.yOffset+"px") | |
} | |
}) | |
}) | |
} | |
}(window.jQuery); | |
(function() { | |
'use strict'; | |
let $ = window.jQuery; | |
GM_addStyle('#preview { position: absolute; border: 2px solid #fff; background: #fff; padding: 4px 4px 4px 4px; display: none; border-radius:5px; color: #fff ;}'); | |
if(window.location.href.indexOf("/details.php?id=") > -1) | |
{ | |
$("#saythank a").click(); | |
$('a[title="Bookmark File"]').remove(); | |
$('a[title="Promote this Torrent"]').remove(); | |
} | |
$("td[width='900'] a img[src='pic/cam.gif '], table.main td[align='left'] a img[src='/pic/cam.gif'], table#torrenttable td a img[src='pic/cam.gif ']").parent().each(function(){ | |
var imageSrc = this.href; | |
$(this).addClass('preview').attr('data-preview',imageSrc);; | |
$(this).parent().children('a:first-child').each(function(){ | |
let subject = $(this); | |
subject.addClass('preview'); | |
subject.attr('data-preview',imageSrc); | |
}); | |
}); | |
$(window).on('resize', function(){ | |
$('.preview').anarchytip(); | |
}); | |
$('.preview').anarchytip(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment