Warning: fopen(/www/sites/update.greasyfork.icu/index/store/forever/cd51eead048818e58d0731ec439cee95.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.1.5.6
// @description 请自己研究尝试
// @author DARK-FLAME-MASTER FROM RIVERSIDE
// @match https://bbs.uestc.edu.cn/forum.php?mod=viewthread*
// @Match *://bbs-uestc-edu-cn-s.vpn.uestc.edu.cn:*/forum.php?mod=viewthread*
// @icon https://www.google.com/s2/favicons?sz=64&domain=uestc.edu.cn
// @require https://cdn.jsdelivr.net/npm/cfb@1.1.3/cfb.js
// @require https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.js
// @license WTFPL
// @run-at document-idle
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_listValues
// @grant unsafeWindow
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
function notice_emoji(text) {
Notification.requestPermission().then((result) => { if (result === 'granted') { let n = new Notification(text); setTimeout(n.close.bind(n), 1800) } })
}
function listFiles(src, allowed_exts = []) {
let f = new FileReader()
let group_name = src[0].name
f.readAsBinaryString(src[0]);
let file_list = [];
f.onload = function () {
let eif = CFB.read(this.result, { type: 'binary' })
let valid_paths = []
let valid_content = eif.FileIndex.filter((e, i) => {
if (e.size > 0) {
valid_paths.push(eif.FullPaths[i])
return true
}
return false
})
let s = new Set()
let file_list_upload = {}
for (let idx in valid_content) {
let entry = valid_content[idx]
let extname = entry.name.substring(entry.name.lastIndexOf(".") + 1)
if (entry.type == 2 && (!allowed_exts || _.indexOf(allowed_exts, extname) >= 0)) {
let name = valid_paths[idx].substring(0, valid_paths[idx].lastIndexOf("."))
if (!s.has(name)) {
let group = valid_paths[idx].match(/Entry\/(\d+)\//)[1]
upload_count += 1
let f = new File([new Uint8Array(entry.content)], entry.name, { type: "image/" + extname })
if (file_list_upload[group]) {
file_list_upload[group].push(f)
} else {
file_list_upload[group] = [f]
}
s.add(name + 'fix')
}
}
}
for (let group in file_list_upload) {
upload_emoji(file_list_upload[group], group_name + group)
}
document.getElementById('progress_upload').hidden = false
document.getElementById('progress_upload').max = upload_count
}
}
function add_emoji(id, src, flag = true, group = 'default') {
return function () {
if (group == 'default') group = selected_group.group
if (!emoji_set[group]) emoji_set[group] = []
emoji_set[group].push([id + 'e', src])
GM_setValue('emoji_set', emoji_set)
group = 'default'
if (flag == true)
notice_emoji('已添加表情')
}
}
function del_emoji(id, group = 'default') {
return function () {
let e = document.getElementById(id)
e.parentNode.removeChild(e)
emoji_set[group] = emoji_set[group].filter((c, i, s) => c[0] != id)
if (emoji_set[group] == 0) del_group(group)
GM_setValue('emoji_set', emoji_set)
notice_emoji('已删除表情')
}
}
function del_group(group) {
return function () {
let msg = "您确定要删除该分组吗?";
if (confirm(msg) == true && emoji_group_list.length > 1) {
let e = document.getElementById(group)
e.parentNode.removeChild(e)
delete emoji_set[group]
if (selected_group.group == group) {
let ind = emoji_group_list.indexOf(group)
emoji_group_list.splice(ind, 1)
if (ind != 0)
selected_group.group = emoji_group_list[ind - 1]
else
selected_group.group = emoji_group_list[0]
}
GM_setValue('emoji_set', emoji_set)
notice_emoji('已删除分组')
}
}
}
function addCss(styleCss) {
let head = document.querySelector('head');
let style = document.createElement('style');
style.type = 'text/css';
let text = document.createTextNode(styleCss);
style.appendChild(text)
head.appendChild(style);
}
function upload_eif(input) {
listFiles(input.target.files, ['jpg', 'gif', 'bmp', 'png'])
}
function upload_emoji_select(input) {
upload_emoji(input.target.files)
}
function upload_emoji(input, group = 'default') {
[].forEach.call(input, function (file) {
file = {
name: file.name,
size: file.size,
type: file.type,
dom: file,
};
let data = new FormData();
for (let k in post_params)
data.append(k, post_params[k]);
data.append('type', 'image')
data.append('filetype', file.type)
data.append('Filename', file.name);
data.append('Filedata', file.dom);
let pid;
fetch("/misc.php?mod=swfupload&action=swfupload&operation=album", {
"headers": {
},
"method": "POST",
"mode": "cors",
"body": data,
"credentials": "include",
}).then((res) => res.json()).then((data) => {
pid = data.picid;
add_emoji(pid, data.bigimg, false, group)();
return fetch("/home.php?mod=spacecp&ac=upload", {
"headers": {
"content-type": "application/x-www-form-urlencoded",
},
"body": "title[" + pid + "]=&albumid="+emoji_album_id+"&albumsubmit=true&albumsubmit_btn=true&formhash=" + formhash,
"method": "POST",
"mode": "cors",
"credentials": "include"
})
}).then((data) => { upload_count -= 1; let p = document.getElementById('progress_upload'); p.value = p.max - upload_count; if (upload_count == 0) notice_emoji('已上传完毕') })
}
)
}
function switch_tag(e) {
let id = e.currentTarget.id
selected_group.group = id
unsafeWindow.setMenuPosition('mine','mine_menu','12!')
}
function update_emoji() {
let emoji_in_group = emoji_set[selected_group.group]
let emoji_data = '
➕
'
let del_emoji_div =document.getElementById('del_emoji_div')
for (let i = 0; i < emoji_in_group.length; ++i) {
let emoji_id = emoji_in_group[i][0]
src = emoji_in_group[i][1]
emoji_data += '