Greasy Fork is available in English.
增强考古加能力
当前为
// ==UserScript==
// @name 考古加助手
// @namespace http://tampermonkey.net/
// @version 1.0
// @license GPL-3.0
// @description 增强考古加能力
// @author wzhjm
// @match https://*.kaogujia.com/*
// @icon https://raw.githubusercontent.com/wzhjm/MWeb_Image/main/202312072020007.ico
// @grant none
// ==/UserScript==
(function () {
'use strict';
var t, s, a, n;
t = document.createElement("script");;
t.src = "https://zeptojs.com/zepto.min.js"
document.body.appendChild(t);
s = document.createElement("script");
s.src = "https://www.itxst.com/package/clipboardjs/clipboard.min.js"
document.body.appendChild(s);
var new_element = document.createElement('link');
new_element.setAttribute('rel', 'stylesheet');
//注:这里currentScript的写法不兼容IE
new_element.setAttribute('href', 'https://unpkg.com/element-ui/lib/theme-chalk/index.css');
document.body.appendChild(new_element);
var copyTxt=function(text){
if(typeof document.execCommand!=="function"){
alert("复制失败,请长按复制");
return;
}
var dom = document.createElement("textarea");
dom.value = text;
dom.setAttribute('style', 'display: block;width: 1px;height: 1px;');
document.body.appendChild(dom);
dom.select();
var result = document.execCommand('copy');
document.body.removeChild(dom);
if (result) {
alert("复制成功");
return;
}
if(typeof document.createRange!=="function"){
alert("复制失败,请长按复制");
return;
}
var range = document.createRange();
var div=document.createElement('div');
div.innerHTML=text;
div.setAttribute('style', 'height: 1px;fontSize: 1px;overflow: hidden;');
document.body.appendChild(div);
range.selectNode(div);
const selection = window.getSelection();
if (selection.rangeCount > 0){
selection.removeAllRanges();
}
selection.addRange(range);
document.execCommand('copy');
alert("复制成功")
}
var videoListFunction = function () {
// 等待zepto加载完,再执行
if ($('.pc-icon-player') && $('.pc-icon-player').forEach) {
$('body').append('<button class="btn" id="urlClipboard" data-clipboard-text="复制的内容">CP</button>');
new ClipboardJS('#urlClipboard');
//全局变量
var originOpen = window.open;
var copyOpen = function (url) {
//将链接转化成原视频链接
url = url.replaceAll('\/share', '').replaceAll('?', '');
$('#urlClipboard').data('clipboard-text', url);
$('#urlClipboard').click();
console.log("已复制:" + url);
}
$('body').on('click', '.check-item', function () {
if ($(this).hasClass('el-icon-check')) {
$(this).removeClass('el-icon-check')
} else {
$(this).addClass('el-icon-check')
}
changeSelect()
})
//添加浮动的选择按钮
$('body').append(`<div class="select-all" style='width: 100px;z-index:999;
height: 50px;
line-height: 50px;
position: fixed;
bottom: 15px;
right: 120px;
color:#4975e9;
cursor: pointer;
background: #ffffff;
text-align: center;
border-radius: 12px;
box-shadow: 0 0 15px 0 hsl(0deg 0% 40% / 10%);'>全选</div>`)
$('body').on('click', '.select-all', function () {
//获取所有
var has_select = false;
$('.check-item').forEach(item => {
if ($(item).hasClass('el-icon-check')) {
has_select = true
}
})
if (has_select) {
//有选择,全部取消
$('.check-item').forEach(item => {
$(item).removeClass('el-icon-check')
})
} else {
//为空,全选
$('.check-item').forEach(item => {
$(item).addClass('el-icon-check')
})
}
$(this).text(!has_select ? "取消选中" : "全选")
})
var changeSelect = function () {
var has_select = false;
$('.check-item').forEach(item => {
if ($(item).hasClass('el-icon-check')) {
has_select = true
}
})
console.log('changeSelect', !has_select ? "取消选中" : "全选")
$('.select-all').text(has_select ? "取消选中" : "全选")
}
//添加浮动的选择复制按钮
$('body').append(`<div class="copy-all" style='width: 100px;
height: 50px;
line-height: 50px;
position: fixed;
bottom: 15px;
right: 0px;
color:#4975e9;
cursor: pointer;
background: #ffffff;
text-align: center;
border-radius: 12px;
box-shadow: 0 0 15px 0 hsl(0deg 0% 40% / 10%);'>复制选中</div>`)
//复制选择
$('body').on('click', '.copy-all', function () {
var copy_list = []
window.open = function (url) {
//将链接转化成原视频链接
url = url.replaceAll('\/share', '').replaceAll('?', '');
copy_list.push(url)
}
//获取所有
$('.check-item').forEach(item => {
if ($(item).hasClass('el-icon-check')) {
$(item).prev().prev().click()
}
}) //复制完成,恢复 window.open
window.open = originOpen
if (copy_list.length > 0) {
copyOpen(copy_list.join('\n'))
}
setTimeout(() => {
if (copy_list.length > 0) {
$(this).text('复制成功')
$(this).css('color', '#67C23A')
//复制成功,取消所有选择
$('.check-item').forEach(item => {
$(item).removeClass('el-icon-check')
})
changeSelect()
} else {
$(this).text('没有选择')
$(this).css('color', '#F56C6C')
}
setTimeout(() => {
$(this).text('复制选中').css('color', '#4975e9')
}, 2000)
}, 1000)
})
setInterval(() => {
$('.goods-box').forEach(pro => {
let is_has = $(pro).parent().find('.cover-click')
if (is_has.length == 0) {
$(pro).parent().css('position', 'relative')
//添加相关视频按钮
$(pro).parent().append(
`<div class="cover-click" style="position: absolute;right: 0px;bottom: 12px;color:#4975e9;z-index: 9999;cursor: pointer;">关联视频<div>`
)
}
})
let player_ele = []
if (location.pathname === '/darenDetails/videoWorks') {
//达人视频作品页面
player_ele = $('.handle-area .svg:nth-child(2) svg')
//调整表格样式
$("colgroup").forEach(col => {
$(col).children().forEach((item, index) => {
if (index > 1 && index < 8) {
$(item).attr('width', 80)
}
if (index == 8) {
$(item).attr('width', 126)
}
})
})
$('thead > tr').children().forEach((item, index) => {
if (index > 1 && index < 8) {
$(item).css('width', 80)
$(item).attr('width', 80)
}
if (index == 8) {
$(item).css('width', 126)
$(item).attr('width', 126)
}
})
$('tbody > tr').children().forEach((item, index) => {
if (index > 1 && index < 8) {
$(item).css('width', 80)
$(item).attr('width', 80)
}
if (index == 8) {
$(item).css('width', 126)
$(item).attr('width', 126)
}
})
player_ele.forEach(player => {
$(player).parent().css('display', 'flex')
$(player).parent().css('align-items', 'center')
})
} else {
player_ele = $('.collect-icon')
}
player_ele.forEach(function (player) {
let is_has = $(player).parent().find('.has-check-item')
//避免因问懒加载的原因导致一些元素没有插入,已经插入的就不需要再次插入。
if (is_has.length === 0) {
$(player).after(
'<i class="check-item" style="display: inline-block;\n' +
' width: 24px;\n' +
' height: 24px!important;\n' +
' border: 1px solid #ddd;\n' +
' border-radius: 4px;\n' +
' text-align: center;\n' +
' line-height: 22px!important;\n' +
' cursor: pointer;' +
'margin-left: 0.5em;"></i>');
$(player).after(
'<i class="has-check-item el-icon-document-copy" onclick="window.open = copyOpen; $(this).prev().click(); window.open = originOpen; $(this).removeClass(\'el-icon-document-copy\').addClass(\'el-icon-check\'); setTimeout(()=>{$(this).removeClass(\'el-icon-check\').addClass(\'el-icon-document-copy\')}, 500);" style="display: inline-block;\n' +
' width: 24px;\n' +
' height: 24px!important;\n' +
' border: 1px solid #ddd;\n' +
' border-radius: 4px;\n' +
' text-align: center;\n' +
' line-height: 22px!important;\n' +
' cursor: pointer;' +
'margin-left: 0.5em;"></i>');
}
});
}, 1000)
let searchGoods = function (goods_name) {
//将goods_name放到搜索框搜索
$($('.search-container').find('.cancel-input-default')[0]).val(goods_name)
$('.search-container').find('.cancel-input-default')[0].dispatchEvent(new Event('input'))
setTimeout(() => {
$('.search-container .search-icon').click()
}, 600)
}
$('body').on('click', '.cover-click', function () {
//获取点击的 title
let title = $(this).parent().find('.title').text()
console.log('title', title)
searchGoods(title)
})
let query = {}
location.search.replace("?", "").split("&").forEach(kv => {
let k_v = kv.split("=")
query[k_v[0]] = k_v[1]
})
if (query.goods_name) {
let goods_name = decodeURIComponent(query.goods_name)
console.log('goods_name', goods_name)
let temp_int = setInterval(() => {
searchGoods(goods_name)
clearInterval(temp_int)
}, 400)
}
}
}
var productOverviewFunction = function () {
let is_has = $('.line-tabs-box').find('.search-video')
if (is_has.length == 0) {
let goods_name = $('.title-box').find('.title').text()
if ($('.line-tabs-box').find('.search-video').length === 0) {
$($('.line-tabs-box').children()[3]).after(
`<div class="search-video line-tabs-item"> <a style="color: #e84a58;text-decoration: none;" href="/darenSquare/videoList?goods_name=` +
goods_name + `" target="_blank">搜索关联视频</a> </div>`
)
}
}
}
var productListFunction = function () {
setInterval(() => {
$('.list-export-item').forEach(pro => {
let is_has = $(pro).parent().find('.cover-click')
if (is_has.length == 0) {
let goods_name = $(pro).find('.title').text()
$(pro).parent().css('position', 'relative')
//添加相关视频按钮
$(pro).parent().append(
`<div style="position: absolute;right: -60px;bottom: 28px;z-index: 999;" flex="cross:center main:center" class="cover-click search-video"> <a style="color: #4975e9;text-decoration: none;" href="/darenSquare/videoList?goods_name=` +
goods_name + `" target="_blank">关联视频</a><div>`
)
}
})
}, 1000)
}
var productAnalysisFunction = function () {
setInterval(() => {
$('.goods-export').forEach(pro => {
let is_has = $(pro).parent().find('.cover-click')
if (is_has.length == 0) {
let goods_name = $(pro).find('.desc').text()
$(pro).parent().css('position', 'relative')
//添加相关视频按钮
$(pro).parent().append(
`<div style="position: absolute;right: -28px;bottom: 15px;z-index: 999;" flex="cross:center main:center" class="cover-click search-video"> <a style="color: #4975e9;text-decoration: none;" href="/darenSquare/videoList?goods_name=` +
goods_name + `" target="_blank">关联视频</a><div>`
)
}
})
}, 1000)
}
window.onload = () => {
var init_list = {
"/darenSquare/productList": {
init: false,
page_load: productListFunction,
},
"/darenSquare/videoList": {
init: false,
page_load: videoListFunction,
},
"/darenDetails/videoWorks": {
init: false,
page_load: videoListFunction,
},
"/darenDetails/productAnalysis": {
init: false,
page_load: productAnalysisFunction,
},
"/productDetails/productOverview": {
init: false,
page_load: productOverviewFunction,
},
"/productDetails/linkDaren": {
init: false,
page_load: productOverviewFunction,
},
"/productDetails/linkLive": {
init: false,
page_load: productOverviewFunction,
},
"/productDetails/linkVideo": {
init: false,
page_load: productOverviewFunction,
},
"/productDetails/productFansPortrait": {
init: false,
page_load: productOverviewFunction,
}
}
console.log('init_list', init_list)
//每个页面有指定的函数,到了这个页面才加载页面函数
var page_object = init_list[location.pathname]
console.log('location.href', location.pathname)
console.log('init', page_object.init)
if (page_object && !page_object.init) {
//未初始化
setTimeout(page_object.page_load, 1000)
page_object.init = true
}
//其他页面 init 切换成false
for (let href in init_list) {
if (href !== location.pathname && init_list[href].init == true) {
console.log(href + ' false')
init_list[href].init = false
}
}
}
})();