Get_all_img_Library

修复清空缓存的逻辑,修复丢失的before_reflash

Verze ze dne 10. 01. 2024. Zobrazit nejnovější verzi.

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.sleazyfork.org/scripts/480132/1309498/Get_all_img_Library.js

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Get_all_img_Library
// @namespace    http://tampermonkey.net/
// @version      2023.11.20
// @description  修复清空缓存的逻辑,修复丢失的before_reflash
// @author       You
// @grant        none
// ==/UserScript==
function get_img_obo_sessionStorage(key,nums,geturl,getimg,putimg){
	if(window.location.href.indexOf(key)<0){return}
	var i = 2
	if(sessionStorage.num){i = Number(sessionStorage.num)}
	var oldimg = $(sessionStorage.img)
	before_reflash(i,oldimg,putimg)
	
	var state = sessionStorage.state
	if(state!='start'){putimg($(sessionStorage.img),0);sessionStorage.clear();return}
	
	if(i<=nums){
		var href = geturl(i)
		if(!href){putimg($(sessionStorage.img),0);sessionStorage.clear();return}
		$.ajax({
			url:href,
			success:function(){
				var img = getimg('')
				if(sessionStorage.img==undefined){sessionStorage.img=""}
				sessionStorage.img += $('<div></div>').append(img.clone()).html()
				window.location.href = href
				i+=1
				sessionStorage.num = i
			},
			error:function(){
				alert(href+' error')
				putimg($(sessionStorage.img),0)
				sessionStorage.clear()
			},
		})
		
	}else{
		putimg($(sessionStorage.img),0)
		sessionStorage.clear()
	}
}
function before_reflash(i,oldimg,putimg){
	if(sessionStorage.reflash){putimg($(sessionStorage.img),0)}

	console.log('before_reflash')
	window.onbeforeunload = function(){
		if(!oldimg){return}
		if(sessionStorage.state){return}
		sessionStorage.img = $('<div></div>').append(oldimg).html()
		sessionStorage.reflash = 'reflash'
		sessionStorage.num = i
	}
}
function get_img_obo_ajax_href(key,nums,geturl,getimg,putimg){
	var obo = function(i){
		var href = geturl(i)
		console.log(href)
		if(!href){return}
		$.ajax({
			url:href,
			success:function(data){
				var img = getimg(data)
				putimg(img,i)
				showmass(i+'/'+nums)
				
				i+=1
				if(i>nums){return}
				obo(i)
			},
			error:function(){
				console.log('error: '+href)
				i+=1
				if(i>nums){return}
				obo(i)
			}
		})
	};obo(0)
}
function new_bottom_bu(text){
	var bu = $('<button></button>').text(text).css({
		position:'fixed',
		bottom:0,
		width:'100vw',
		height:'10vh',
		'font-size':'5vh'
	})
	return bu
}
function obo_sessionStorage_start_bu(){
	var bu = new_bottom_bu("start")
	bu.click(function(){
		if(sessionStorage.state!='start'){
			sessionStorage.clear()
			sessionStorage.setItem('state','start')
			location.reload()
		}else{
			sessionStorage.clear()
		}
	})
	return bu
}
function showmass(ms) {
	if($('.mass_top').attr('class')){$('.mass_top').text(ms);return}
	$('body').append($('<div class="mass_top"></div>').css({
		'font-size':'2vw',
		'color':'rgba(0, 102, 0, 0.5)',
		'position':'fixed',
		'top':'10px',
		'left':'10px',
		'font-weight':'bold',
		'z-index':99999999,
	}).click(function(){$(this).hide()}))
	$('.mass_top').text(ms)
}
function add_css(tag,object){
	var style = $('<style></style>').text(tag+JSON.stringify(object).replace(/\"/g,'').replace(/,/g,";"))
	$('body').append(style)
}
function remove_sameimg(){
	var hs = new Array()
	$('img').each(function(){
		if(hs.indexOf(this.src)<0){
			hs.push(this.src)
		}else{
			$(this).remove()
		}
	})
}
function reflash_unloadimg(){
	var check = setInterval(function(){
		if(sessionStorage.reflashlock == 'yes'){return}
		var img = $('img:visible').filter(function(){return this.naturalWidth==0})
		img.each(function(){
			if(this.naturalWidth==0){
				//console.log(this.src)
				var clone = $(this).clone(true)
				var parent = $(this).parent()
				var pre = $(this).prev()
				var next = $(this).next()
				$(this).remove()
		
				setTimeout(function(){
					if(pre[0]){pre.after(clone);return}
					if(next[0]){next.before(clone);return}
					if(parent[0]){parent.append(clone);return}
				},500)
			}
		})
	},1000)
}
window.GAIL = {
	get_img_obo_sessionStorage : get_img_obo_sessionStorage,
	get_img_obo_ajax_href : get_img_obo_ajax_href,
	new_bottom_bu : new_bottom_bu,
	obo_sessionStorage_start_bu : obo_sessionStorage_start_bu,
	showmass : showmass,
	add_css : add_css,
	remove_sameimg : remove_sameimg,
	reflash_unloadimg : reflash_unloadimg,
}