// ==UserScript==
// @name cool18
// @version 2025.11.24.01
// @description 修复预览bug
// @author You
// @include https://www.cool18.com/*
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_getValue
// @grant GM_download
// @grant GM_xmlhttpRequest
// @require https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js
// @require https://update.greasyfork.org/scripts/480132/1534996/Get_all_img_Library.js
// ==/UserScript==
/**
* @description 修复搜索页显示不了图片的bug
*/
let overriderPhone1 = true;
let run = false;
/**
* @description 2025-11-23 改成点击再加载
*/
let overriderPhone2 = true;
$(function(){
document.addEventListener("touchstart",()=>{if(!run){run=true;get_home_img()}});
if($(window).width()>$(window).height()){
$(body).on('mousewheel',function(){$(this).trigger('touchstart')});
}else{
let bu = $('').css({
'position':'fixed',
'right':'5vw',
'bottom':'5vw'
})
$('body').append(bu);
bu.click(GetListImg);
}
})
function get_home_img(){
const key = "cool18";
let atag = $(".l-m1>a:first-child");
let nums = atag.length;
if(overriderPhone1){
if(nums==0){
atag = $('.t_subject a');
nums = atag.length;
if(nums==0) console.log("no fond atag");
}
atag.attr('target','_blank');
}
const Geturl = (i)=>{
atag.eq(i).css('background-color','green');
return atag.eq(i)[0].href;
}
const Getimg = (doc)=>{
return $(doc).find('center img:not([src*="gif"])').eq(0);
}
const Putimg = (img,i)=>{
atag.eq(i).after(img);
img.click(function(){$(this).prev()[0].click();})
}
if(overriderPhone2){
atag.each(function(){
const a = $(this);
const bu = $('').css({
width:'100%',
height:'10vw'
})
.click(()=>{
bu.text('loading');
atag = a.attr('showed','yes');
get_img_obo_ajax_href(key,1,Geturl,Getimg,Putimg);
})
a.after(bu);
})
const bu = $('').css({
width:'100%',
height:'5vw'
})
.click(()=>{
atag = $(".l-m1>a:not[showed]");
if(atag.length==0) return;
get_img_obo_ajax_href(key,atag.length,Geturl,Getimg,Putimg);
})
$('.thread-list:first').before(bu).after(bu.clone(true));
}else get_img_obo_ajax_href(key,nums,Geturl,Getimg,Putimg);
$(".l-m2,.l-m3").hide()
let Add_css = ()=>{
let css = `
`
$("body").append(css);
}
Add_css()
}
function GetListImg(){
let img = $('center img:not([ccc])');
if(img.length==0) return;
let random = Math.floor(Math.random()*1000);
let i = 0;
let t = 0;
img.each(function(){
$(this).attr('ccc','yes');
let src = this.src;
let et = src.match(/\.[^\.]+$/)[0];
let name = document.title + (random+i) + et;
console.log(name);
i++;
GM_download({
url:src,
name:name,
onload:function(){$('.mass_top').txt((++t)+"/"+img.length);$('.mass_top').css('font-size','5vw')}
});
});
}