// ==UserScript==
// @name 查房脚本
// @namespace https://www.gamemale.com/space-uid-714849.html
// @homepage https://www.gamemale.com/thread-??????-1-1.html
// @version 2024-07-21
// @description 这个是空间相关的脚本。功能:1.强制显示空间的导航栏(若未生效,则尝试使用功能2)。 2.可消除空间的自定义样式。(在油猴菜单中操作,或是使用快捷键‘Ctrl键’)。 3.查看回帖时的跳转,若未找到则自动继续定位回帖的所在楼层。
// @author u
// @match https://www.gamemale.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=gamemale.com
// @grant GM_registerMenuCommand
// ==/UserScript==
(function() {
'use strict';
let spaceuid=document.getElementById('domainurl')?.search.substr(1);
//if(spaceuid==discuz_uid)return;
if(!spaceuid){
if(location.hash.startsWith('#pid')&&location.search.startsWith('?mod=viewthread')){
if(!document.getElementById(location.hash.substring(1))){
const url =new URL(window.location.href);
let page = parseInt(url.searchParams.get('page'));
if(page==document.querySelector('#pgt strong').textContent){
url.searchParams.set('page',page+1);
location.href=url;
}
}
}
return;
}
let spacecss=document.getElementById('diy_style').innerHTML;
if(isBlocked()){document.getElementById('diy_style').innerHTML='';document.querySelector('link').href='template/mwt2/extend/img/lslogo.png';}
document.getElementById('nv').innerHTML=`<ul><li><a style='color:inherit !important' href="/home.php?mod=space&uid=${spaceuid}&do=index">空间首页</a></li>
<li><a style='color:inherit !important' href="/home.php?mod=space&uid=${spaceuid}&do=home&view=me&from=space">动态</a></li>
<li><a style='color:inherit !important' href="/home.php?mod=space&uid=${spaceuid}&do=doing&view=me&from=space">记录</a></li>
<li><a style='color:inherit !important' href="/home.php?mod=space&uid=${spaceuid}&do=blog&view=me&from=space">日志</a></li>
<li><a style='color:inherit !important' href="/home.php?mod=space&uid=${spaceuid}&do=album&view=me&from=space">相册</a></li>
<li><a style='color:inherit !important' href="/home.php?mod=space&uid=${spaceuid}&do=thread&view=me&from=space">主题</a></li>
<li><a style='color:inherit !important' href="/home.php?mod=space&uid=${spaceuid}&do=wall">留言板</a></li>
<li><a style='color:inherit !important' href="/home.php?mod=space&uid=${spaceuid}&do=profile">个人资料</a></li></ul>`;
document.getElementById('nv').style.visibility='initial';
document.getElementById('nv').style.display='initial';
//document.getElementById('nv').style.zIndex='1';
function getBlockList(){return JSON.parse(localStorage.getItem('uSpaceBlocked')||'[]');}
function setBlockList(list){localStorage.setItem('uSpaceBlocked',JSON.stringify([...list]));}
function removecss(){document.getElementById('diy_style').innerHTML='';}
function addcss(){document.getElementById('diy_style').innerHTML=spacecss;}
function isBlocked(){return getBlockList().includes(spaceuid);}
function showMsg(m){showPrompt(null,null,`<i>${m}</i>`, 1300);}
function addToBlockList(){
if(isBlocked()){showMsg('此空间已在黑名单中。');return;}
let t = getBlockList();
t.push(spaceuid);
setBlockList(t);
removecss();
showMsg('现已将此空间加入黑名单。');
document.querySelector('link').href='template/mwt2/extend/img/lslogo.png';
}
function deleteFromBlockList(){
if(!isBlocked()){showMsg('未在黑名单中找到此空间。');return;}
let t = new Set(getBlockList());
t.delete(spaceuid);
setBlockList(t);
addcss();
showMsg('现已将此空间从黑名单中移除。');
document.querySelector('link').href='template/mwt2/extend/img/favicon.ico';
}
let blockTexts=['打入冷宫!','即刻杖毙!','逐出宫门!','秽乱后宫,罪不容诛!'];
GM_registerMenuCommand(blockTexts[Math.floor(Math.random()*blockTexts.length)],addToBlockList);
GM_registerMenuCommand('看她有没有重新做人',deleteFromBlockList);
let ctrlMark = false;
document.addEventListener('keydown', (e) => {ctrlMark = e.key === 'Control'});
document.addEventListener('keyup', (e)=>{if(e.key === 'Control' && ctrlMark){
if(isBlocked())deleteFromBlockList();else addToBlockList();
}});
})();