1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 | /** * 噗浪表符整理器 v0.10.4.1 (20210219) * ============== * 利用噗浪本身的JS/HTML砌成,以便批量管理表符 * 僅限於桌面版使用 * * 功能: * - 批量移動、刪除群組內的表符 * - 表符及群組排序 * - 設定群組圖示 * - 利用噗首或噗內留言中的表符去新增/移動/刪除表符 * - 顯示表符總數 * - 多行顯示所有表符群組 * * 備註: * 1. 程式沒有加入60/1000的上限檢查(也沒進行測試),表符庫爆掉沒有提示,請自行檢查 * 2. 成功與錯誤都沒有訊息提示 * 3. 此script重度依賴噗浪桌面版的JS/HTML,日後噗浪改版可能會無法使用(例如沒有反應) */ javascript:(function(){ window.custPlugin = window.custPlugin || {}; window.custPlugin.emo = window.custPlugin.emo || $(); window.custPlugin.emo.extend({ getGroupIdByEmo: function(url){ var hash = this.getHashFromURL(url); var allEmos = EmoticonCustom.getEmoticons(); for (var grpId in allEmos){ for (var emo of allEmos[grpId]){ if (hash == emo['hash_id']){ return grpId; } } } return -1; }, getEmoByUrl: function(url){ var hash = this.getHashFromURL(url); var allEmos = EmoticonCustom.getEmoticons(); for (var grpId in allEmos){ for (var emo of allEmos[grpId]){ if (hash == emo['hash_id']){ return emo; } } } return null; }, isEmoExists: function(url){ return this.getGroupIdByEmo(url) > 0; }, isEmoInGroup: function(url, grpId){ var resultGroupId = this.getGroupIdByEmo(url); return resultGroupId > 0 && resultGroupId == grpId; }, getHashFromURL: function(url){ if (url !== undefined && url.length > 0){ return url.substring(url.lastIndexOf('/')+1, url.indexOf('_')); } }, getEmoTotalCount: function(){ var total = 0; for (let grp of EmoticonCustom.getGroups()){ total += EmoticonCustom.getEmoticons(grp.id).length; } return total; }, refreshEmoticon: function(){ console.info('Refresh EmoticonCustom...'); window.EmoticonCustom.load(true); window.setTimeout(function () { custPlugin.emo.initEmoPanel(); }, 2000); }, addEmo: async function(hashId, groupId, keyword){ var postResult = await $.post("/Emoticons/add",{form_token:top.SiteState.getToken(), hash_id: hashId, keyword: keyword, group_id: groupId}).promise(); return postResult; }, setEmoGroup: async function(hashId, groupId){ var postResult = await $.post("/EmoticonManager2/setGroup",{token:top.SiteState.getToken(), hash_id: hashId, group_id: groupId}).promise(); return postResult; }, setOrder: async function(hashId, afterHashId){ var postResult = await $.post("/EmoticonManager2/setOrder",{token:top.SiteState.getToken(), hash_id: hashId, after_hash_id: afterHashId}).promise(); return postResult; }, newGroup: async function(){ var postResult = await $.post("/EmoticonManager2/newGroup",{token:top.SiteState.getToken()}).promise(); return postResult; }, removeGroup: async function(groupId){ var postResult = await $.post("/EmoticonManager2/revokeGroup",{token:top.SiteState.getToken(), group_id: groupId}).promise(); return postResult; }, setGroupOrder: async function(hashId, afterHashId){ var postResult = await $.post("/EmoticonManager2/setGroupOrder",{token:top.SiteState.getToken(), group_id: hashId, after_group_id: afterHashId}).promise(); return postResult; }, setGroupThumbail: async function(hashId, groupId){ var postResult = await $.post("/EmoticonManager2/setThumbnail",{token:top.SiteState.getToken(), thumbnail_hash_id:hashId, group_id: groupId}).promise(); return postResult; }, batchAddEmo: async function(emosUrl, groupId){ if (emosUrl.length > 0) { if (groupId == 0){ let newGrpResp = await this.newGroup(); if (!newGrpResp.ok){ return; } groupId = newGrpResp.g; console.info('Group ' + groupId + ' is added.'); } for (const url of emosUrl) { this.addToQueue({action: "add", url: url, groupId: groupId, keyword: ''}); } this.addMoveEmo(); } }, addMoveEmoQueue: [], addToQueue: function(data){ this.addMoveEmoQueue.push(data); }, addMoveQueueRunning: false, addMoveEmo: async function(){ if (this.addMoveQueueRunning){ return; } this.addMoveQueueRunning = true; if (this.addMoveEmoQueue.length == 0){ custPlugin.emo.refreshEmoticon(); this.addMoveQueueRunning = false; } else{ var queueObj = this.addMoveEmoQueue.shift(); var hashId = this.getHashFromURL(queueObj.url); var groupId = queueObj.groupId; if (queueObj.action == "add"){ if (EmoticonCustom.isFull()){ console.info('Emoticon has reached max limit. Add emoticon is not allowed.'); } else{ let resp = await this.addEmo(hashId, groupId, queueObj.keyword); console.info(resp.keyword + ' is added.'); } } else if (queueObj.action == 'move'){ let resp = await this.setEmoGroup(hashId, groupId); console.info(this.getEmoByUrl(queueObj.url).keyword + ' is moved to group=' + groupId); } else if (queueObj.action == 'setOrder'){ let resp = await this.setOrder(hashId, queueObj.afterHashId); console.info(this.getEmoByUrl(queueObj.url).keyword + ' is sorted.'); } this.addMoveQueueRunning = false; this.addMoveEmo(); } }, removeEmo: function(){ console.info('removeEmo'); var counter = this.deleteEmoQueue.length; while (this.deleteEmoQueue.length > 0) { var url = this.deleteEmoQueue.shift(); var hashId = this.getHashFromURL(url); var _self = this; $.ajax({ url: "/Emoticons/remove", method: "POST", data: {token:top.SiteState.getToken(), hash_id:hashId}, dataType: "json", vCustomData: {url: url} }) .done(function(resp){ console.info(_self.getEmoByUrl(this.vCustomData.url).keyword + ' is deleted.'); counter = counter - 1; if (counter == 0){ custPlugin.emo.refreshEmoticon(); } }); } }, deleteEmoQueue: [], batchDeleteEmoByIds: function(emosUrl){ if (emosUrl.length > 0) { for (const url of emosUrl) { this.deleteEmoQueue.push(url); } this.removeEmo(); } }, batchDeleteEmoByGrpId: async function(){ var emoGroupId = this.getSelectedEmoGrpId(); var _self=this; if (emoGroupId !== undefined && emoGroupId > 1){ $.post("/EmoticonManager/getUserEmoticons",{token:top.SiteState.getToken()}).done(async function(emos){ if (emos[emoGroupId] !== undefined){ for (const e of (emos[emoGroupId])) { _self.deleteEmoQueue.push(e.url); } _self.removeEmo(); } }); await _self.removeGroup(emoGroupId); console.info('Group [' + emoGroupId + '] is deleted.'); custPlugin.emo.refreshEmoticon(); } }, batchSetEmoGroup: async function(emosUrl, groupId){ if (emosUrl.length > 0) { if (groupId == 0){ let newGrpResp = await this.newGroup(); if (!newGrpResp.ok){ return; } groupId = newGrpResp.g; console.info('Group ' + groupId + ' is added.'); } for (const url of emosUrl) { this.addToQueue({action: "move", url: url, groupId: groupId}); } this.addMoveEmo(); } }, setEmoGroupThumbail: async function(emoUrl){ if (emoUrl.length > 0) { let groupId = this.getGroupIdByEmo(emoUrl); let resp = await this.setGroupThumbail(this.getHashFromURL(emoUrl), groupId); console.info(this.getEmoByUrl(emoUrl).keyword + ' is set as thumbnail of group=' + groupId); custPlugin.emo.refreshEmoticon(); } }, setEmoGroupOrder: async function(groupId, afterGroupId){ let resp = await this.setGroupOrder(groupId, afterGroupId); console.info('Group ' + groupId + ' is sorted.'); custPlugin.emo.refreshEmoticon(); }, getSelectedEmoGrpId: function(){ return $('#emoticon-tabs li.current[emo-group-type="custom"]').attr('emo-group-id'); }, isCustomEmoGrpSelected: function(){ var emoGroupId = this.getSelectedCustomEmoGrpId(); return emoGroupId !== undefined && emoGroupId > 0; }, getCounterNode: function(){ var counterNode = document.querySelector('#emoCounter'); if (counterNode == undefined){ var newNode = document.createElement("DIV"); newNode.id = "emoCounter"; var postNode = document.querySelector('#emoticon-selector-holder .manager-button'); postNode.parentNode.insertBefore(newNode, postNode); $(newNode).css({ position : "absolute", right: "150px", top: "12px", lineHeight: "26px" }); counterNode = newNode; } return counterNode; }, updateCounterNode: function(groupType, groupId){ var counterNode = this.getCounterNode(); var html = ''; if (groupType == 'custom'){ html = '群組' + groupId + ':' + EmoticonCustom.getEmoticons(groupId).length + '/' + this.getEmoTotalCount(); } else{ html = this.getEmoTotalCount(); } $(counterNode).html(html); }, updateTogglePanel: function(groupType, groupId){ if (groupType == undefined && groupId == undefined){ groupType = $('#emoticon-tabs li.current').attr('emo-group-type'); groupId = $('#emoticon-tabs li.current').attr('emo-group-id'); } var plug = custPlugin.emo; var btnConfig = this.panelElement.button; var enableDelMoveBtn = (this.selectedEmos.size > 0 && this.emoPanelMode == 'edit'); var enableDelGrpBtn = (groupType == 'custom' && groupId > 1 && this.emoPanelMode == 'edit'); var enableGrpThumbailBtn = (this.selectedEmos.size == 1 && this.emoPanelMode == 'edit'); var enableSortBtn = (groupType == 'custom'); var selectedArr = Array.from(this.selectedEmos); if (this.selectedEmos.size == 0 && groupId == 1){ enableSortBtn = false; } if (enableSortBtn){ for (var i=0; i<selectedArr.length; i++){ if (this.getGroupIdByEmo(selectedArr[i]) != groupId){ enableSortBtn = false; } } } this.updatePanelButton(btnConfig.move, enableDelMoveBtn); this.updatePanelButton(btnConfig.delete, enableDelMoveBtn); this.updatePanelButton(btnConfig.deleteGroup, enableDelGrpBtn); this.updatePanelButton(btnConfig.groupThumbail, enableGrpThumbailBtn); this.updatePanelButton(btnConfig.sortEmo, enableSortBtn); }, emoPanelMode: "default", updateEmoHolderPanel: function(groupType){ if (!document.getElementById('customEmoOperatePanel')){ return; } if (this.emoPanelMode == 'edit'){ $('#emoticons-holder li').off("click", custPlugin.emo.editEmoMode); $('#emoticons-holder li').on("click", custPlugin.emo.editEmoMode); } if (groupType == undefined){ groupType = $('#emoticon-tabs li.current').attr('emo-group-type'); } if (groupType != 'custom'){ return; } if (this.selectedEmos.size > 0){ var allLi = $('#emoticons-holder li'); var liList = []; for (let i = 0; i < allLi.length; i++) { var li = $(allLi[i]); let imgSrc = li.find("img").attr('src'); if (this.selectedEmos.has(imgSrc)){ liList.push(li); } } if (liList.length > 0){ this.selectEmoticons(liList); } } }, getTogglePanelNode: function(groupType, groupId){ var plug = this; var panel = $('<div />', { id: "customEmoOperatePanel", class: "header", css: { display: "block", position: "relative", width: "100%", height: "50px", }, }); var selectAllSection = $('<div />', {class: "selectAll-section"}); selectAllSection.append($('<a>',{ text: "全選", css: { userSelect: "none", color: '#FF574D', }, on: { click: plug.selectAllEmoticons, }, })); var separatorSection = $('<div>|</div>'); var selectInfoSection = $('<div />', { class: "select-info-section", text: "已選取:0", }); var btnPanelSection = $('<div />', {class: "button-section"}); var btnConfig = this.panelElement.button; btnPanelSection.append(this.getPanelButton(btnConfig.sortEmo, true)); btnPanelSection.append(this.getPanelButton(btnConfig.groupThumbail, true)); btnPanelSection.append(this.getPanelButton(btnConfig.move, true)); btnPanelSection.append(this.getPanelButton(btnConfig.delete, true)); btnPanelSection.append(this.getPanelButton(btnConfig.deleteGroup, true)); panel.append(selectAllSection); panel.append(separatorSection); panel.append(selectInfoSection); panel.append(btnPanelSection); panel.find('> div').css({ display: "table-cell", padding: "0 5px", height: "40px", verticalAlign: "middle", }); separatorSection.css({ padding: "0", }); btnPanelSection.css({ position: "absolute", right: "0", top: "11px", }); btnPanelSection.find('> div').css({ display : "inline-block", }); return panel; }, showEmoSelectorPanelPopup: function(fromEle, emos, usage){ var ele = $('<div id="custEmoSelectorPanel" class="emo-adder"><div class="emo-adder-panel"><div class="emo-groups"><div class="emo-message"></div></div></div></div>'); if (emos.length == 0 && usage != 'deleteGroup') { $('div.emo-message', ele).append('未選擇表符'); } else{ var emoUrls = Array.from(emos); if (usage == 'move'){ $('div.emo-message', ele).append('已選擇 ' + emoUrls.length + ' 個表符,移至群組:<br />'); var ul = $('<ul></ul>'); var groups = EmoticonCustom.getGroups(); groups[groups.length] = {id: 0}; for (var grp of groups){ var li; if (grp['id'] == 0){ li = $('<li emo-group-id="0"><span class="new-group pif-add" /></li>'); } else { li = $('<li emo-group-id="' + grp['id'] + '"><img src="' + grp['thumbnail'] + '"/></li>'); } li.on('click', function(evt){ evt.stopPropagation(); var groupId = $(this).attr('emo-group-id'); $('#custEmoSelectorPanel').remove(); custPlugin.emo.batchSetEmoGroup(emoUrls, groupId); custPlugin.emo.clearSelectedEmos(); }); ul.append(li); } $('div .emo-groups', ele).append(ul); } else if (usage == 'delete'){ $('div.emo-message', ele).append('確定刪除選擇的 ' + emoUrls.length + ' 個表符?'); var buttonPanel = $('<div class="buttons" />'); var delBtn = $('<div class="button small-button pif-delete">刪除</div>'); delBtn.on('click', function(evt){ evt.stopPropagation(); $('#custEmoSelectorPanel').remove(); custPlugin.emo.batchDeleteEmoByIds(emoUrls); custPlugin.emo.clearSelectedEmos(); }); buttonPanel.append(delBtn); var cancelBtn = $('<div class="add-button button small-button pif-cancel">取消</div>'); cancelBtn.on('click', function(evt){ evt.stopPropagation(); $('#custEmoSelectorPanel').remove(); }); buttonPanel.append(cancelBtn); $('div.emo-groups', ele).append(buttonPanel); } else if (usage == 'deleteGroup'){ $('div.emo-message', ele).append('確定刪除整個群組,以及群組內的所有表符?'); var buttonPanel = $('<div class="buttons" />'); var delGrpBtn = $('<div class="button small-button pif-delete">刪除</div>'); delGrpBtn.on('click', function(evt){ evt.stopPropagation(); $('#custEmoSelectorPanel').remove(); custPlugin.emo.batchDeleteEmoByGrpId(); custPlugin.emo.clearSelectedEmos(); }); buttonPanel.append(delGrpBtn); var cancelBtn = $('<div class="add-button button small-button pif-cancel">取消</div>'); cancelBtn.on('click', function(evt){ evt.stopPropagation(); $('#custEmoSelectorPanel').remove(); }); buttonPanel.append(cancelBtn); $('div.emo-groups', ele).append(buttonPanel); } } var popView = new PopView({ content: ele, exClass: 'pop-tooltip', direction: 'bottom', keep: false, hoverArea: true, }); popView.showFrom(fromEle); }, updateTogglePanelBtnNode: function(groupType, groupId){ var node = $('#'+this.panelElement.button.togglePanel.id); if (!node.length){ node = this.getPanelButton(this.panelElement.button.togglePanel); var plug = this; node.off('click'); node.on('click', function(evt){ var panel = $('#customEmoOperatePanel'); if (panel.length){ panel.remove(); $(this).text('*'); plug.emoPanelMode = 'default'; plug.leaveSortMode(); $('#emoticons-holder li').off("click", custPlugin.emo.editEmoMode); custPlugin.emo.clearSelectedEmos(); } else{ var panel = plug.getTogglePanelNode(); $('#emoticon-selector-holder .header').after(panel); $(this).text('-'); plug.emoPanelMode = 'edit'; plug.leaveSortMode(); plug.updateTogglePanel(); plug.updateEmoHolderPanel(groupType); } }); $('#emoticon-selector-holder .manager-button').before(node); } this.updateTogglePanel(groupType, groupId); this.updateEmoHolderPanel(groupType); return node; }, panelElement: { button: { move: { id: 'emoGrpBatchMove', text: "移動", css: { background: "#64a590", color: "#FFF", }, on: { click: function(evt) { var emos = custPlugin.emo.selectedEmos; custPlugin.emo.showEmoSelectorPanelPopup(this, emos, 'move'); }, }, }, groupThumbail: { id: 'emoGrpSetThumbnail', text: "圖示", css: { background: "#AB8E7C", color: "#FFF", }, on: { click: function(evt) { var emos = custPlugin.emo.selectedEmos; if (emos.size == 1){ custPlugin.emo.setEmoGroupThumbail(emos.keys().next().value); custPlugin.emo.clearSelectedEmos(); } else{ alert('必須選取 1 個表符。'); } }, }, }, sortEmo: { id: 'emoSortEmo', text: "排序", css: { background: "#9762a7", color: "#FFF", }, on: { click: function(evt) { if (custPlugin.emo.emoPanelMode == 'edit'){ custPlugin.emo.initSortMode(); } else if (custPlugin.emo.emoPanelMode == 'sort'){ custPlugin.emo.leaveSortMode(); } }, }, }, delete: { id: "emoGrpBatchDelete", text: "刪除", css: { background: "#7182c1", color: "#FFF", }, on: { click: function(evt) { var emos = custPlugin.emo.selectedEmos; custPlugin.emo.showEmoSelectorPanelPopup(this, emos, 'delete'); }, }, }, deleteGroup: { id: "emoGrpBatchDeleteWithGrp", text: "刪除群組", css: { background: "#434343", color: "#FFF", }, on: { click: function(evt) { var emos = custPlugin.emo.selectedEmos; custPlugin.emo.showEmoSelectorPanelPopup(this, emos, 'deleteGroup'); }, }, }, togglePanel: { id: "emoTogglePanel", text: "*", css: { position : "absolute", right: "45px", top: "11px", background: "#ff8d06", width: "30px", } }, css: { common: { color: "#FFF", lineHeight: "26px", padding: "0 5px", marginRight: "5px", borderRadius: "4px", textAlign: "center", fontSize: "13px", cursor: "pointer", }, enabled: { opacity: '1', cursor: "pointer", }, disabled: { opacity:'0.3', cursor: "default", } }, } }, getPanelButton: function(btn, isInit){ var node = $('#'+btn.id); if (!node.length){ node = $('<div />', btn); node.css(this.panelElement.button.css.common); node.css(btn.css); } if (isInit){ node.off("click"); node.css(this.panelElement.button.css.disabled); } return node; }, updatePanelButton: function(btn, isEnable){ var node = $('#'+btn.id); node.off("click"); if (isEnable){ node.on("click", btn.on.click); node.css(this.panelElement.button.css.enabled); } else{ node.css(this.panelElement.button.css.disabled); } }, updateEmoPanel: function(grpType, grpId){ if (grpType == undefined && grpId == undefined){ grpType = $('#emoticon-tabs li.current').attr('emo-group-type'); grpId = $('#emoticon-tabs li.current').attr('emo-group-id'); } if (this.emoPanelMode == 'sort'){ if ($('#emoticons-holder li.dummy').length == 0 || $('#emoticon-tabs li.dummy').length == 0){ this.initSortMode(); } } else{ this.updateCounterNode(grpType, grpId); this.updateTogglePanelBtnNode(grpType, grpId); } }, initEmoPanel: function(){ if (document.querySelector('#emoticon-tabs li.current') != undefined){ $('#emoticon-tabs li[emo-group-type]').on( "click", function() { let grpType = $(this).attr('emo-group-type'); let grpId = $(this).attr('emo-group-id'); }); custPlugin.emo.updateEmoPanel(); } }, addEmoPanelToHeader: function(){ var eleClass = "#permanent-holder .divplurk"; var ele = document.querySelector(eleClass); if (ele == undefined){ eleClass = ".cbox_plurk_holder .divplurk"; ele = document.querySelector(eleClass); } if (ele == undefined){ eleClass = ".plurk_box.display"; ele = document.querySelector(eleClass); } if (ele != undefined && document.querySelector(eleClass + " .emoPanelInHeader") == undefined){ var containerNode = $( "<span class='emoPanelInHeader'></span>" ); var addEmoNode = $( "<span class='emoBtn addEmo' title='新增或移動表符'>⭐</span>" ); var removeEmoNode = $( "<span class='emoBtn removeEmo' title='刪除表符'>❌</span>" ); var emos = Object.values(document.querySelectorAll(eleClass + ' .text_holder img.emoticon_my')); addEmoNode.on("click", function(evt) { evt.stopPropagation(); custPlugin.emo.showEmoGroupPopup(this, emos, 'add'); }); removeEmoNode.on("click", function(evt) { evt.stopPropagation(); custPlugin.emo.showEmoGroupPopup(this, emos, 'delete'); }); containerNode.append(addEmoNode); containerNode.append(removeEmoNode); $(eleClass + ' .time').append(containerNode); $(eleClass + ' .emoPanelInHeader .emoBtn').css({ padding: "0 2px", margin: "0 2px", background: "transparent", color: "#FFF", borderRadius: "4px", cursor: "pointer", textAlign: "center", fontSize: "13px", fontWeight: "600", display: "inline-block", width: "24px", opacity: emos.length > 0 ? "1" : "0.3", }); $(eleClass + ' .emoPanelInHeader .emoBtn').hover(function() { $(this).css("background-color","#b6e2dc"); }, function(){ $(this).css("background-color","transparent"); }); } }, addEmoPanelToComment: function(){ var node = document.querySelector('#emoPanelInComment'); if (node == undefined){ let respManagerEle = document.querySelector('.show-response-manager'); if (respManagerEle != null){ var containerNode = $( "<span id='emoPanelInComment'></span>" ); var addEmoNode = $( "<span class='emoBtn addEmo' title='新增或移動表符'>⭐</span>" ); var removeEmoNode = $( "<span class='emoBtn removeEmo' title='刪除表符'>❌</span>" ); var emos = Object.values(document.querySelectorAll('.show-response-manager .text_holder img.emoticon_my')); addEmoNode.on("click", function() { custPlugin.emo.showEmoGroupPopup(this, emos, 'add'); }); removeEmoNode.on("click", function() { custPlugin.emo.showEmoGroupPopup(this, emos, 'delete'); }); containerNode.append(addEmoNode); containerNode.append(removeEmoNode); $('.show-response-manager .time').after(containerNode); $('#emoPanelInComment .emoBtn').css({ padding: "0 2px", margin: "0 2px", background: "transparent", color: "#FFF", borderRadius: "4px", cursor: "pointer", textAlign: "center", fontSize: "13px", fontWeight: "600", display: "inline-block", width: "24px", opacity: emos.length > 0 ? "1" : "0.3", }); $('#emoPanelInComment .emoBtn').hover(function() { $(this).css("background-color","#b6e2dc"); }, function(){ $(this).css("background-color","transparent"); }); } } }, showEmoGroupPopup: function(fromEle, emos, usage){ var ele = $('<div id="custEmoGrpPanel" class="emo-adder"><div class="emo-adder-panel"><div class="emo-groups"><div class="emo-message"></div></div></div></div>'); if (emos.length == 0) { $('div.emo-message', ele).append('未選擇留言/留言沒有表符'); } else{ var emoUrls = Array.from(new Set(emos.map(e => e.src))); if (usage == 'add'){ $('div.emo-message', ele).append('留言內有 ' + emoUrls.length + ' 個表符<br />'); var ul = $('<ul></ul>'); var groups = EmoticonCustom.getGroups(); groups[groups.length] = {id: 0}; for (var grp of groups){ var li; if (grp['id'] == 0){ li = $('<li emo-group-id="0"><span class="new-group pif-add" /></li>'); } else { li = $('<li emo-group-id="' + grp['id'] + '"><img src="' + grp['thumbnail'] + '"/></li>'); } li.on('click', function(evt){ evt.stopPropagation(); var groupId = $(this).attr('emo-group-id'); var toAddEmos = emoUrls.filter(s => !custPlugin.emo.isEmoExists(s)); var toMoveEmos = emoUrls.filter(s => custPlugin.emo.isEmoExists(s) && !custPlugin.emo.isEmoInGroup(s, groupId)); if (toAddEmos.length > 0){ custPlugin.emo.batchAddEmo(toAddEmos, groupId); } if (toMoveEmos.length > 0){ custPlugin.emo.batchSetEmoGroup(toMoveEmos, groupId); } $('#custEmoGrpPanel').remove(); }); ul.append(li); } $('div .emo-groups', ele).append(ul); } else if (usage == 'delete'){ $('div.emo-message', ele).append('確定刪除留言內包含的 ' + emoUrls.length + ' 個表符?'); var toDelEmos = emoUrls.filter(s => custPlugin.emo.isEmoExists(s)); var buttonPanel = $('<div class="buttons" />'); var delBtn = $('<div class="button small-button pif-delete">刪除</div>'); delBtn.on('click', function(evt){ evt.stopPropagation(); if (toDelEmos.length > 0){ custPlugin.emo.batchDeleteEmoByIds(toDelEmos); } $('#custEmoGrpPanel').remove(); }); buttonPanel.append(delBtn); var cancelBtn = $('<div class="add-button button small-button pif-cancel">取消</div>'); cancelBtn.on('click', function(evt){ evt.stopPropagation(); $('#custEmoGrpPanel').remove(); }); buttonPanel.append(cancelBtn); $('div.emo-groups', ele).append(buttonPanel); } } var popView = new PopView({ content: ele, exClass: 'pop-tooltip', direction: 'bottom', keep: false, hoverArea: true, }); popView.showFrom(fromEle); }, selectedEmos: new Set(), editEmoMode: function(evt){ evt.stopPropagation(); var groupType = $('#emoticon-tabs li.current').attr('emo-group-type'); if (groupType != 'custom'){ return; } var li = $(evt.target).closest('li'); var imgSrc = li.find("img").attr('src'); if (li.hasClass('selectedItem')){ custPlugin.emo.deselectEmoticons([li], true); } else{ custPlugin.emo.selectEmoticons([li], true); } }, updateSelectCounter: function(){ var infoSection = $('#customEmoOperatePanel .select-info-section'); if (infoSection.length){ infoSection.text('已選取:' + custPlugin.emo.selectedEmos.size); } }, selectEmoticons: function(liArr, addSelected){ for (var i=0; i<liArr.length; i++){ var li = $(liArr[i]); li.addClass('selectedItem'); li.css({ boxShadow: "inset 0px 0px 0px 3px #f9ada9", filter: "brightness(0.9)" }); if (addSelected){ var imgSrc = li.find("img").attr('src'); custPlugin.emo.selectedEmos.add(imgSrc); } } if (addSelected){ custPlugin.emo.updateSelectCounter(); custPlugin.emo.updateTogglePanel(); } }, deselectEmoticons: function(liArr, removeSelected){ for (var i=0; i<liArr.length; i++){ var li = $(liArr[i]); li.removeClass('selectedItem'); li.css({ boxShadow: "", filter: "" }); if (removeSelected){ var imgSrc = li.find("img").attr('src'); custPlugin.emo.selectedEmos.delete(imgSrc); } } if (removeSelected){ custPlugin.emo.updateSelectCounter(); custPlugin.emo.updateTogglePanel(); } }, selectAllEmoticons: function(evt){ var liList = $('#emoticons-holder li'); if (liList.length == 0){ return; } var nonSelectedLiList = liList.not('.selectedItem'); if (nonSelectedLiList.length > 0){ var liArr = Object.values(nonSelectedLiList).filter(e => e.tagName=='LI'); custPlugin.emo.selectEmoticons(liArr, true); } else { var liArr = Object.values(liList).filter(e => e.tagName=='LI'); custPlugin.emo.deselectEmoticons(liArr, true); } }, clearSelectedEmos: function(){ custPlugin.emo.selectedEmos.clear(); var liList = $('#emoticons-holder li'); if (liList.length > 0){ var liArr = Object.values(liList).filter(e => e.tagName=='LI'); custPlugin.emo.deselectEmoticons(liArr, true); } }, initSortMode: function(){ $('#emoticons-holder li').off("click", custPlugin.emo.editEmoMode); this.emoPanelMode = 'sort'; var btn = this.getPanelButton(this.panelElement.button.sortEmo); btn.text('取消'); this.updateTogglePanel(); var virtualLi; if (this.selectedEmos.size > 0){ virtualLi = $('#emoticons-holder li.virtualEmo'); if (virtualLi.length == 0){ $('#emoticons-holder ul').append($('<li>', { class: "dummy", css: { height: '1px', width: '1px', }, })); $('#emoticons-holder li').off("mouseover", this.sortEmoMode); $('#emoticons-holder li').on("mouseover", this.sortEmoMode); } } var groupId = $('#emoticon-tabs li.current').attr('emo-group-id'); if (groupId != '1'){ virtualLi = $('#emoticon-tabs li.virtualGrp'); if (virtualLi.length == 0){ $('#emoticon-tabs ul').append($('<li>', { class: "dummy", css: { height: '1px', width: '1px', }, })); $('#emoticon-tabs li').off("mouseover", this.sortGroupMode); $('#emoticon-tabs li').on("mouseover", this.sortGroupMode); } } }, leaveSortMode: function(){ $('#emoticons-holder li').off("mouseover", this.sortEmoMode); $('#emoticons-holder li.virtualEmo').remove(); $('#emoticons-holder li.dummy').remove(); $('#emoticon-tabs li').off("mouseover", this.sortGroupMode); $('#emoticon-tabs li.virtualGrp').remove(); $('#emoticon-tabs li.dummy').remove(); var btn = this.getPanelButton(this.panelElement.button.sortEmo); btn.text('排序'); this.updateTogglePanel(); this.emoPanelMode = 'edit'; $('#emoticons-holder li').on("click", custPlugin.emo.editEmoMode); }, batchSetEmoOrder: function(afterHashId){ this.selectedEmos.delete(afterHashId); if (this.selectedEmos.size > 0){ var emosUrl = Array.from(this.selectedEmos).reverse(); for (const url of emosUrl) { this.addToQueue({action: 'setOrder', url: url, afterHashId: afterHashId}); } this.addMoveEmo(); } this.clearSelectedEmos(); }, sortGroupMode: function(evt){ evt.stopPropagation(); var groupType = $('#emoticon-tabs li.current').attr('emo-group-type'); if (groupType != 'custom'){ return; } var li = $(evt.target).closest('li'); if (li.hasClass('virtualGrp') || li.attr('emo-group-type') != 'custom' || li.attr('emo-group-id') == '1'){ return; } if (li.prevAll('.virtualGrp').length > 0){ li = li.next(); } var virtualLi = $('#emoticon-tabs li.virtualGrp'); if (virtualLi.length == 0){ virtualLi = $('<li>', { class: "virtualGrp", }); var span = $('<span>',{ text: '+', css: { display: "inline-block", width: "20px", height: "20px", textAlign: "center", verticalAlign: "middle", backgroundColor: "#fff3f1", border: "2px dashed #E48686", borderRadius: "2px", }, }); virtualLi.append(span); } else{ virtualLi.remove(); } li.before(virtualLi); virtualLi.off('click'); virtualLi.on('click', function(e){ e.stopPropagation(); var groupId = $('#emoticon-tabs li.current').attr('emo-group-id'); var prev = $(this).prev(); var afterGroupId = (prev.length == 0) ? '1' : prev.attr('emo-group-id'); custPlugin.emo.setEmoGroupOrder(groupId, afterGroupId); }); }, sortEmoMode: function(evt){ evt.stopPropagation(); var groupType = $('#emoticon-tabs li.current').attr('emo-group-type'); if (groupType != 'custom'){ return; } var li = $(evt.target).closest('li'); if (li.hasClass('virtualEmo')){ return; } if (li.prevAll('.virtualEmo').length > 0){ li = li.next(); } var virtualLi = $('#emoticons-holder li.virtualEmo'); if (virtualLi.length == 0){ virtualLi = $('<li>', { class: "virtualEmo", "emo-keyword": "-移動到這裡-", css: { border: "2px dashed #E48686", backgroundColor: "#fff3f1", fontSize: "16px", }, text: '+', }); } else{ virtualLi.remove(); } li.before(virtualLi); virtualLi.off('click'); virtualLi.on('click', function(e){ e.stopPropagation(); var prev = $(this).prev(); var afterHashId = (prev.length == 0) ? ' ' : custPlugin.emo.getHashFromURL(prev.find("img").attr('src')); custPlugin.emo.batchSetEmoOrder(afterHashId); custPlugin.emo.leaveSortMode(); }); }, }); if (!document.querySelector('#emoticon-tabs li.current')){ EmoticonSelector.toggleFrom(); } new MutationObserver(function (mutations, me) { if (document.querySelector('#emoticon-tabs li.current')){ custPlugin.emo.initEmoPanel(); me.disconnect(); } }).observe(document, {childList: true, subtree: true }); new MutationObserver(function (mutations, me) { if (document.getElementsByClassName('show-response-manager').length > 0){ custPlugin.emo.addEmoPanelToComment(); } if (!document.getElementById('permanent-holder') || !document.querySelector('#permanent-holder .divplurk .emoPanelInHeader')){ custPlugin.emo.addEmoPanelToHeader(); } }).observe(document, {childList: true, subtree: true }); new MutationObserver(function (mutations, me) { if (document.getElementById('emoticons-holder')){ new MutationObserver(function (mutations2, me2) { custPlugin.emo.updateEmoPanel(); }).observe(document.getElementById('emoticons-holder'), {childList: true, subtree: true }); me.disconnect(); } }).observe(document, {childList: true, subtree: true }); window.custPlugin = window.custPlugin || {}; window.custPlugin.emo = window.custPlugin.emo || $(); window.custPlugin.emo.extend({ emoHolderRow: 3, addEmoHolderExpander: function(){ var expander = $('#emoHolderExpander'); if (expander.length){ return; } expander = $('<div>', { id: "emoHolderExpander", css: { position : "absolute", right: "90px", top: "5px", } }); var moreRowBtn = $('<div>', { text: '▲', }); var lessRowBtn = $('<div>', { text: '▼', }); expander.append(moreRowBtn); expander.append(lessRowBtn); expander.find('> div').css({ width: '20px', height: '16px', textAlign: 'center', backgroundColor: '#92a0ab', color: '#FFF', margin: '2px 0', borderRadius: '3px', cursor: 'pointer', userSelect: 'none', }); moreRowBtn.on('click', function(evt){ if (evt.ctrlKey){ custPlugin.emo.fixEmoHolderRow(); } else{ var row = (evt.shiftKey) ? 7 : 1; custPlugin.emo.changeEmoHolderRow(row); } }); lessRowBtn.on('click', function(evt){ if (evt.ctrlKey){ custPlugin.emo.fixEmoHolderRow(); } else{ var row = (evt.shiftKey) ? -7 : -1; custPlugin.emo.changeEmoHolderRow(row); } }); expander.find('> div').hover(function(){ $(this).css('background-color', '#5abfff') }, function(){ $(this).css('background-color', '#92a0ab') }); $('#emoticon-selector-holder .manager-button').after(expander); }, fixEmoHolderRow: function(){ var needRows = Math.floor(($('#emoticons-holder li').length - 1) / 7 + 1); if (this.emoHolderRow == needRows){ this.emoHolderRow = 3; } else{ this.emoHolderRow = needRows; } this.changeEmoHolderHeight(this.emoHolderRow); }, changeEmoHolderRow: function(i){ this.emoHolderRow = this.emoHolderRow + i; if (this.emoHolderRow > 7){ this.emoHolderRow = 7; } else if (this.emoHolderRow < 3){ this.emoHolderRow = 3; } this.changeEmoHolderHeight(this.emoHolderRow); }, changeEmoHolderHeight: function(rows){ if (rows >= 7){ $('#emoticons-holder').css('height', '384px'); } else if (rows == 6){ $('#emoticons-holder').css('height', '330px'); } else if (rows == 5){ $('#emoticons-holder').css('height', '276px'); } else if (rows == 4){ $('#emoticons-holder').css('height', '222px'); } else{ $('#emoticons-holder').css('height', ''); } }, addEmoGroupExpander: function(){ var leftArrow = $('#emoticon-tabs .tabs-arrow-left'); if (leftArrow.hasClass('plug-expander')){ return; } leftArrow.addClass('plug-expander'); var emoTabHeight = $('#emoticon-tabs').css('height'); var emoTabUlWhiteSpace = $('#emoticon-tabs ul').css('white-space'); leftArrow.hover(function(){ if ($(this).hasClass("disabled")){ $(this).removeClass('pif-back'); $(this).removeClass('disabled'); $(this).addClass('pif-option'); } }, function(){ if ($(this).hasClass("pif-option")){ $(this).removeClass('pif-option'); $(this).addClass('pif-back'); $(this).addClass('disabled'); } }); leftArrow.on('click', function(evt){ if ($(this).hasClass("pif-option")){ $(this).removeClass('pif-option'); $(this).addClass('pif-arrow-up'); $('#emoticon-tabs').css('height', 'auto'); $('#emoticon-tabs ul').css('white-space', 'normal'); } else if ($(this).hasClass("pif-arrow-up") && evt.originalEvent !== undefined){ $(this).removeClass('pif-arrow-up'); $(this).addClass('pif-option'); $('#emoticon-tabs').css('height', emoTabHeight); $('#emoticon-tabs ul').css('white-space', emoTabUlWhiteSpace); } }); }, }); new MutationObserver(function (mutations, me) { if (document.querySelector('#emoticon-tabs li.current')){ custPlugin.emo.addEmoGroupExpander(); custPlugin.emo.addEmoHolderExpander(); me.disconnect(); } }).observe(document, {childList: true, subtree: true }); })() |
Direct link: https://paste.plurk.com/show/J7O1APv5kilKSHg0vvI9