Skip to content

Instantly share code, notes, and snippets.

@Ray941216
Created May 15, 2024 01:38
Show Gist options
  • Save Ray941216/a563951cfdf6b52a4f4f6ecb02b5732f to your computer and use it in GitHub Desktop.
Save Ray941216/a563951cfdf6b52a4f4f6ecb02b5732f to your computer and use it in GitHub Desktop.
用法: 1. 在 Chrome 或 Edge 瀏覽器,新增一個書籤到書籤列 2. 編輯該書籤,將網址列清空,先打上『 javascript: 』,然後貼上以下程式碼 3. 到未讀公文清單頁面,可依照需求發動: A. 勾選 想要自動讀取的公文,點擊這個書籤 B. 全部不勾選(留白) 則整頁清空
/* 用法:
* 在 Chrome 或 Edge 瀏覽器,新增一個書籤到書籤列
* 編輯該書籤,將網址列清空,先打上『 javascript: 』,然後貼上以下程式碼
* 到未讀公文清單頁面,可依照需求發動:
* 1. 勾選 想要自動讀取的公文,點擊這個書籤
* 2. 全部不勾選(留白) 則整頁清空
*/
if (confirm("自動完成本頁『已勾選』/『全部』公文確認作業?(確定後請等待完成通知)")) {
var cnt = 0;
var cnt2 = 0;
var ok = function (args) {
var tid = args[0];
var ele = args[1];
var targ = `https://emsodas.cht.com.tw/Portal/PopupPages/TaskPopup/ConfirmPopup.aspx?TaskID=${tid}&title=確認`;
$.ajax({
"url": targ,
"type": "GET",
"success": function (resp) {
var submitButtonValue = $(resp).find('#ctl00_PlaceHolderMain_Button1').val();
if (submitButtonValue !== undefined) {
++cnt2;
var targ2 = `https://emsodas.cht.com.tw/Portal/PopupPages/TaskPopup/ConfirmPopup.aspx?${$(resp).find("#aspnetForm").prop('action').split("aspx?")[1]}`;
console.log(targ2);
formData = $(resp).find("#aspnetForm").serializeArray();
var submitButtonValue = $(resp).find('#ctl00_PlaceHolderMain_Button1').val();
formData.push({ name: $(resp).find('#ctl00_PlaceHolderMain_Button1').prop('name'), value: submitButtonValue });
setTimeout(function(){
$.ajax({
"url": targ2,
"type": "POST",
"data": formData,
"success": function () {
$(ele).html(`✅ ${$(ele).html()}`);
$(`#chk${tid}`).parent().html("✅");
}
})
}, 100)
}
else {
$(ele).html(`✅ ${$(ele).html()}`);
$(`#chk${tid}`).parent().html("✅");
}
}
})
};
var allIds = $(".DocSubject.DocSubject.DocSubject > a").map(function() {
if (this.href.indexOf("?ID") > -1) {
var tid = this.href.split("?ID=")[1];
return {"tid": tid, "elem": this};
}
}).get();
allIdsDict = {};
for (let id_cnt = 0; id_cnt < allIds.length; id_cnt++) {
allIds[id_cnt];
allIdsDict[allIds[id_cnt].tid] = allIds[id_cnt];
}
if ($(".Chk").children(":checked").length > 0) {
var checkedIds = $(".Chk").children(":checked").map(function() {
return allIdsDict[this.id.replace("chk", "")];
}).get();
}
else {
var checkedIds = allIds;
}
checkedIds.forEach(
(a) => {
$(`#chk${a.tid}`).parent().html(`<div id="chk${a.tid}">🔄</div>`);
setTimeout(ok, 500 * (checkedIds.indexOf(a) + 1), [a.tid, a.elem]);
++cnt;
}
);
setTimeout(function () {
setTimeout(function () {
alert(`已完成本頁 ${cnt} 份公文確認作業!\n已完成 ${cnt2} 份公文傳閱確認作業`);
location.reload();
}, 500 * (cnt2 + 1));
}, (500 * (cnt + 3)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment