xchina

good

2024-04-20 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

// ==UserScript==
// @name        xchina
// @version      2024.4.21
// @author       You
// @description  good
// @include     https://xchina.co/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_deleteValue
// @grant        GM_download
// @grant        GM_xmlhttpRequest
// @connect       *
// @require     https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js
// @require		https://code.jquery.com/jquery-3.6.0.min.js
// @require     https://update.greasyfork.org/scripts/480132/1349340/Get_all_img_Library.js
// @namespace https://greasyfork.org/users/1210231
// ==/UserScript==
$(function(){
	add_bu()
		.click(()=>{sessionStorage.setItem('startAjax','true');location.reload(true)})  //先清除缓存,再ajax
		
	if(sessionStorage.getItem('startAjax')=='true'){get_list(get_big_img);sessionStorage.setItem('startAjax','false')}  //判断是否ajax
})
function add_bu(){
	let bu = $('<button>Ajax10</button>')
			.css({
				width:'100%',
				'font-size':'10vw'
			})
	$('.photos').before(bu)
	return bu
}
function get_list(callback){
	if(window.location.href.match(/xchina\.co\/photo\/id-\w+\.html/g)){}else{sessionStorage.removeItem('page');return}
	
	let key = "xchina"
	let atag = $('a.next[href]:first')
	let nums = (()=>{
					if(atag.length>0&&atag.prev().length>0){
						return Number(atag.prev().text())
					}else{
						return 1
					}
				})()
	atag = $('a[current="true"]:first')
	if(atag.length==0){callback($('.photos').children());return}
	$('.photos').children().remove()
	//page记录当前ajax到了第几页
	let page = sessionStorage.getItem('page')
	if(!page){page=0}else{page = Number(page)}
	if(page>=nums){page=0}
	
	let geturl = function(i){
					if(i+page==nums||i==10){sessionStorage.setItem('page',i+page);return false} //超出总页数或10页就退出
					return atag[0].href.replace(/\d+(?=\.)/,(i+1+page))
				}
	let getimg = function(data){return $(data).find('.photos').children().attr('ccc','yes')}
	let putimg = function(img,i){
		$('.photos').append(img)
		$('.mass_top').css('font-size','10vw')

		$('.photos').children('*:not([ccc])').remove()
		$('*:not(.download_bu,.mass_top)').filter(function(){return $(this).css('position')=="fixed"}).remove()
		callback(img)
	}
	window.GAIL.get_img_obo_ajax_href(key,nums,geturl,getimg,putimg)
}
function get_big_img(img){
	let iimg = img.find('img')
	iimg.each(function(){
        let parent = $(this).parent().before($(this).attr('big','yes'))
        parent.hide()
		$(this).attr('big_src',this.src.replace(/_[^\.]+/g,"").replace(/\w+$/g,"jpg"))
		//this.src = this.src.replace(/_[^\.]+/g,"").replace(/\w+$/g,"jpg")
		$('body').append($('<p></p>').text(this.src))
		$(this).parents('a:first[href]').removeAttr('href')
		$(this).click(function(){
			let name = document.title + ".jpg"
			let src = $(this).attr('big_src')
			let _this = this
			GM_download({
				url:src,
				name:name,
				onload:()=>{$(_this).remove()}
			})
		})
	})

	$(".push-bottom").remove()
	return

}
function checkimg_unloaded(){
	let checking = function(){
		let img = $('img[big]:visible').filter(function(){return this.naturalWidth == 0})
		if(img.length>0){
			img.each(function(){
				var clone = $(this).clone(true)
				$(this).after(clone)
				$(this).remove()
				clone[0].scrollIntoView()
			})
		}else{}
	}
	let check = setInterval(checking,500)
}
function del_ad(){
	$('*:not(.download_bu,.mass_top)').filter(function(){return $(this).css('position')=="fixed"}).remove()
}
$('body').on('touchstart',del_ad);