Warning: fopen(/www/sites/update.greasyfork.icu/index/store/forever/b5b8fcc696577e9c51d879faab33e1cb.js): failed to open stream: No space left on device in /www/sites/update.greasyfork.icu/index/scriptControl.php on line 65
// ==UserScript==
// @name 清水河畔表情包计划
// @namespace http://tampermonkey.net/
// @version 0.3.4
// @description 请自己研究尝试
// @author DARK-FLAME-MASTER FROM RIVERSIDE
// @match *://*.uestc.edu.cn/forum.php?mod=viewthread*
// @match *://*.uestc.edu.cn/forum.php?mod=post*
// @icon https://www.google.com/s2/favicons?sz=64&domain=uestc.edu.cn
// @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.slim.min.js
// @require https://cdn.jsdelivr.net/npm/cfb@1.2.2/dist/cfb.min.js
// @require https://cdn.jsdelivr.net/npm/vue@3.2.41/dist/vue.global.min.js
// @license WTFPL
// @run-at document-body
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_listValues
// @grant unsafeWindow
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
unsafeWindow.Vue = Vue
let setAddedImg;
let storageVar = "emojiSet";
let storageAlbum = "emojiAlbum"
let storageGroup = "selectedGroup"
let defaultEmoji = [{ tag: "default", tagImg: { id: 'default', src: 'data/attachment/common/star/common_25_icon.png' }, images: [] }]
//GM_setValue('version','0.1')
let version = GM_getValue('version', 'NULL')
if (version != '0.3' && version != 'NULL') {
let emoji_set = GM_getValue(storageVar)
for (let group of emoji_set)
for (let imgs of group.images)
imgs.size = 0
GM_setValue(storageVar, emoji_set)
}
GM_setValue('version', '0.3')
document.addEventListener('DOMContentLoaded', function () {
let post_params = unsafeWindow.upload.settings.post_params;
let emoji = GM_getValue(storageVar, defaultEmoji)
let emojiAlbum = GM_getValue(storageAlbum, -1)
let selectedGroup = GM_getValue(storageGroup, 0)
let formhash = $('#modactions :nth-child(1)').attr('value');
$('body').prepend(`
` )
Vue.createApp({
data() {
return {
//version,
menu:
{
left: 0,
top: 0,
visible: false
},
emojiSize: [100, 400],
emojiVisible: false,
emojiChangePosInfo: { index: -1, flag: false },
addedImg: { id: 'default', src: 'data/attachment/common/star/common_25_icon.png' },
uploadTotalCount: 0,
uploadNowCount: 0,
renameGroup: false,
emojiAlbum: emojiAlbum,
selectedGroup: selectedGroup < 0 ? 0 : selectedGroup,
selectedEmoji: -1,
formhash: formhash,
post_params: post_params,
emojiTemp: [],
emoji: emoji.length == 0 ? defaultEmoji : emoji
}
},
methods: {
switchTag(index) {
this.selectedGroup = index
},
switchEmoji(index) {
this.selectedEmoji = index
},
delEmoji(index, group = this.selectedGroup) {
this.emoji[group].images.splice(index, 1)
},
addEmoji(emoji, group = this.selectedGroup, notice = false) {
this.emoji[group].images.unshift(emoji)
if (notice) this.notice(`已将表情添加至${this.emoji[group].tag}`)
},
addGroup(group) {
this.emoji.push(group)
return this.emoji.length - 1
},
delGroup(index) {
if (confirm(`您确定要删除分组${this.emoji[index].tag}吗?`)) {
if (index == this.emoji.length - 1 && index != 0) this.selectedGroup -= 1
this.emoji.splice(index, 1)
this.notice("已删除该分组")
}
},
emoAsTagImg(img, group = this.selectedGroup) {
this.emoji[group].tagImg = img
},
changeEmoSize(index) {
let imgs = this.emoji[this.selectedGroup].images
imgs[index].size = (imgs[index].size + 1) % this.emojiSize.length
},
changeEmoPos(index, event) {
this.emojiChangePosInfo.index = index
this.emojiChangePosInfo.flag = true
},
changeEmoPosInGroup(index, event) {
let images = this.emoji[this.selectedGroup].images
if (event.deltaY < -100)
if (index != 0) {
images[index] = images.splice(index - 1, 1, images[index])[0];
this.emojiChangePosInfo.index--
}
if (event.deltaY > 100)
if (index != images.length - 1) {
images[index] = images.splice(index + 1, 1, images[index])[0];
this.emojiChangePosInfo.index++
}
},
insertEmojiInForum(emoji, event) {
let img = event.currentTarget
let h = img.naturalHeight
let w = img.naturalWidth
let size = this.emojiSize[emoji.size]
let min = Math.max(Math.min(h, w), size)
h = Math.ceil(h / min * size)
w = Math.ceil(w / min * size)
eval(`if(typeof insertHrImage == 'undefined')
seditor_insertunit(document.getElementById('postat') != null ? 'post' : 'fastpost' ,'[img=${w},${h}]${emoji.src}[/img]')
else
insertText('
')
`)
},
notice(message) {
Notification.requestPermission().then((result) => { if (result === 'granted') { let n = new Notification(message); setTimeout(n.close.bind(n), 1800) } })
},
setEmojiAlbum() {
emojiAlbum = prompt('请输入表情保存的相册ID:')
if (emojiAlbum != null) {
this.emojiAlbum = emojiAlbum
GM_setValue(storageAlbum, emojiAlbum)
notice("相册设置成功")
}
},
rebuildEmojiByAlbum(album) {
let group = this.addGroup({ tag: album, tagImg: { id: 'default', src: 'data/attachment/common/star/common_25_icon.png' }, images :[]})
fetch("/home.php?mod=space&uid=237640&do=album&id=" + album)
.then(data => data.text())
.then(data => {
let regex = /共 (\d*) 张图片/
let num = parseInt(data.match(regex)[1])
for(let i = 0; i <= (num-1) / 20; ++i){
fetch(`/home.php?mod=space&uid=237640&do=album&id=${album}&page=${i+1}`)
.then(data => data.text())
.then(data => {
let doc = new DOMParser().parseFromString(data, 'text/html');
if(i != parseInt(num / 20)){
for(let j = 1; j <= 20; ++j)
this.addEmoji({id: i*20 + j,src : doc.querySelector(`#ct > div.mn > div > div.bm_c > ul > li:nth-child(${j}) > a > img`).src ,size : 0},group)
}else{
for(let j = 1; j <= num % 20; ++j)
this.addEmoji({id: i*20 + j,src : doc.querySelector(`#ct > div.mn > div > div.bm_c > ul > li:nth-child(${j}) > a > img`).src ,size : 0},group)
}
})
}
})
},
getFiles(event) {
return event.target.files
},
uploadFiles(files, group) {
this.uploadTotalCount += 2 * files.length;
for (let i = 0; i < files.length; ++i) {
let file = {
name: files[i].name,
size: files[i].size,
type: files[i].type,
dom: files[i],
};
let data = new FormData();
for (let k in this.post_params)
data.append(k, this.post_params[k]);
data.append('type', 'image');
data.append('filetype', file.type)
data.append('Filename', file.name);
data.append('Filedata', file.dom);
let pid, src;
fetch("/misc.php?mod=swfupload&action=swfupload&operation=album", {
"headers": {
},
"method": "POST",
"mode": "cors",
"body": data,
"credentials": "include",
}).then((res) => res.json()).then((data) => {
this.uploadNowCount += 1;
pid = data.picid;
src = data.bigimg;
return fetch("/home.php?mod=spacecp&ac=upload", {
"headers": {
"content-type": "application/x-www-form-urlencoded",
},
"body": "title[" + pid + "]=&albumid=" + this.emojiAlbum + "&albumsubmit=true&albumsubmit_btn=true&formhash=" + this.formhash,
"method": "POST",
"mode": "cors",
"credentials": "include"
})
}).then((data) => { this.emojiTemp.push({ group: group, img: { id: pid, src: src, size: 0 } }); this.uploadNowCount += 1; })
}
},
uploadEif(files, allowedExts = []) {
let f = new FileReader()
f.readAsBinaryString(files[0]);
let addGroup = this.addGroup
let uploadFiles = this.uploadFiles
f.onload = function () {
let eif = CFB.read(this.result, { type: 'binary' })
let validPaths = []
let validContent = eif.FileIndex.filter((e, i) => {
if (e.size > 0) {
validPaths.push(eif.FullPaths[i])
return true
}
return false
})
let s = new Set()
let fileList = {}
for (let idx in validContent) {
let entry = validContent[idx]
let extName = entry.name.substring(entry.name.lastIndexOf(".") + 1)
if (entry.type == 2 && (!allowedExts || allowedExts.includes(extName))) {
let name = validPaths[idx].substring(0, validPaths[idx].lastIndexOf("."))
if (!s.has(name)) {
let group = validPaths[idx].match(/Entry\/(\d+)\//)[1]
let f = new File([new Uint8Array(entry.content)], entry.name, { type: "image/" + extName })
if (fileList[group]) {
fileList[group].push(f)
} else {
fileList[group] = [f]
}
s.add(name + 'fix')
}
}
}
for (let group in fileList) {
uploadFiles(fileList[group], addGroup({ tag: group, tagImg: { id: 'default', src: 'data/attachment/common/star/common_25_icon.png' }, images: [] }))
}
}
},
setAddedImg(img) {
this.addedImg = img
},
openMenu(e, item) {
this.rightClickItem = item;
let x = e.pageX;
let y = e.pageY;
this.menu.top = y;
this.menu.left = x;
this.menu.visible = true;
},
closeMenu() {
this.menu.visible = false;
}
},
watch: {
uploadNowCount(newCount) {
if (newCount == this.uploadTotalCount) {
for (let data of this.emojiTemp) {
this.addEmoji(data.img, data.group)
}
this.emojiTemp = []
this.notice("表情上传完成")
this.uploadNowCount = 0
this.uploadTotalCount = 0
}
},
'menu.visible'(value) {
if (value) {
document.body.addEventListener('click', this.closeMenu)
} else {
document.body.removeEventListener('click', this.closeMenu)
}
},
selectedGroup(newIndex) {
GM_setValue(storageGroup, newIndex)
},
emoji: {
handler(newEmoji, oldEmoji) {
if (newEmoji.length == 0)
this.emoji = newEmoji = defaultEmoji
GM_setValue(storageVar, newEmoji)
},
deep: true
}
},
mounted() {
setInterval(() => console.log("运行中"), 1000)
this.prompt = prompt
setAddedImg = this.setAddedImg
console.log(this.emoji)
},
computed: {
progress() {
return this.uploadTotalCount != 0 ? this.uploadNowCount / this.uploadTotalCount : 0
},
position() {
return this.emojiVisible ? { left: this.$refs.mine.getBoundingClientRect().left + 'px', bottom: unsafeWindow.innerHeight - this.$refs.mine.getBoundingClientRect().top - document.documentElement.scrollTop + 'px' } : {}
},
}
}).mount('#emojiTemplate');
document.body.style.overflowX = 'hidden'
})
function makeReplyEmoji() {
document.addEventListener('DOMContentLoaded', () => $('#fastpostat').before($('#mine')))
setTimeout(function () {
$('.t_f>img.zoom').each(function (i) { $(this.previousSibling).after($('').append($(this))) })
$('ignore_js_op>img').each(function (i) { $(this.previousSibling).after($('').append($(this))) })
$('.emojiImg').mouseenter(function () {
let length = Math.min(this.firstChild.clientWidth, this.firstChild.clientHeight)
$('#likeEmo').css({
'font-size': length * 0.15 + 'px',
'left': 0,
'top': -this.firstChild.clientHeight + 10 + 'px',
'position': 'absolute',
'cursor': 'pointer',
'display': 'inline',
})
setAddedImg({ id: $(this.firstChild).attr('id'), src: $(this.firstChild).attr('src'), size: 0 })
$(this).append($('#likeEmo'))
})
$('.emojiImg').mouseleave(function () {
$('#likeEmo').css('display', 'none')
$('#mine_menu').append($('#likeEmo'))
})
$('#fastpostsubmit').click(function () { if (!$('#mine_menu')[0].style.display) $('#mine').trigger('click') })
}, 500)
return Promise.resolve()
}
function makePostEmoji() {
document.addEventListener('DOMContentLoaded', () => {
$("#e_sml").after($('#mine'))
$('#mine').css('font-size', '25px')
})
return Promise.resolve()
}
let trueHideWindow = unsafeWindow.hideWindow
unsafeWindow.hideWindow = function (k, all, clear) {
if (k == 'reply') {
$('#fastpostat').before($('#mine'))
if (!$('#mine_menu')[0].style.display) $('#mine').trigger('click')
}
trueHideWindow(k, all, clear)
}
let trueShowMenu = unsafeWindow.showMenu
unsafeWindow.showMenu = function (v) {
trueShowMenu(v)
if (v.menuid == 'fwin_reply')
$('#postat').before($('#mine'))
}
let trueDoane = unsafeWindow.doane;
unsafeWindow.doane = function (e, preventDefault, stopPropagation) {
stopPropagation = isUndefined(stopPropagation) ? 0 : stopPropagation;
return trueDoane(e, preventDefault, stopPropagation)
}
let emojiHandler = [
{
regex: /https:\/\/.*\.uestc\.edu\.cn\/forum\.php\?mod=viewthread.*/i,
handler: makeReplyEmoji,
},
{
regex: /https:\/\/.*\.uestc\.edu\.cn\/forum\.php\?mod=post.*/i,
handler: makePostEmoji,
},
]
function matchHandlers(url) {
for (let { regex, handler } of emojiHandler) {
let match = url.match(regex);
if (match) {
return handler();
}
}
return Promise.reject();
}
matchHandlers(unsafeWindow.location.href)
//setInterval(function(){$('#postat').before($('#mine'))},1000)
})();