Arca base64 autodecoder

Arca.live Base64 auto decoder

当前为 2023-12-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Arca base64 autodecoder
  3. // @name:ko 아카라이브 Base64 자동 디코더
  4. // @version 1.202
  5. // @author Laria
  6. // @match https://arca.live/b/*/*
  7. // @description Arca.live Base64 auto decoder
  8. // @description:ko 아카라이브 Base64 자동 복호화 스크립트
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=arca.live
  10. // @license MIT
  11. // @encoding utf-8
  12. // @run-at document-end
  13. // @supportURL https://greasyfork.org/ko/scripts/482577-arca-base64-autodecoder
  14. // @namespace https://greasyfork.org/users/1235854
  15. // @grant GM.getValue
  16. // @grant GM.setValue
  17. // @grant GM.registerMenuCommand
  18. // @grant GM.unregisterMenuCommand
  19. // ==/UserScript==
  20.  
  21. /*
  22. * == Change log ==
  23. * 1.0 - Release
  24. * 1.1 - Invalid character update (replace -> replaceAll)
  25. * 1.11 - Improved show multiple links
  26. * 1.12 - Show Single links Bugfix
  27. * 1.13 - Bugfix 1.12
  28. * 1.14 - Base64 add padding func
  29. * 1.15 - Add annotation, display improvements
  30. * 1.16 - Display improved - CSS applied
  31. * 1.17 - var safe, max_iter defined (~7, def:3)
  32. * 1.18 - auto update check, log system
  33. * 1.20 - add menu(base64 depth, user-drag auto decoding, hide encoded link, update notify)
  34. * 1.201 - base64 depth extends - 11, temporary disable - drag auto decoding
  35. * 1.202 - improve encoded link click callback, feature block in edit mode, enable drag auto decoding
  36. */
  37.  
  38. //base64 encoded(http:/*, https:/*) string prefix
  39. const regArr = [
  40. /(aHR0cDovL|aHR0cHM6Ly)(\w|=|\+|\/)*(?=[^\+=\w\/])/g, //encoding 1 time
  41. /(YUhSMGNEb3ZM|YUhSMGNITTZMe)(\w|=|\+|\/)*(?=[^\+=\w\/])/g, //encoding 2 time
  42. /(WVVoU01HTkViM1pN|WVVoU01HTklUVFpNZ)(\w|=|\+|\/)*(?=[^\+=\w\/])/g, //encoding 3 time
  43. /(V1ZWb1UwMUhUa1ZpTTFwT|V1ZWb1UwMUhUa2xVVkZwTl)(\w|=|\+|\/)*(?=[^\+=\w\/])/g, //encoding 4 time
  44. /(VjFaV2IxVXdNVWhVYTFacFRURndU|VjFaV2IxVXdNVWhVYTJ4VlZrWndUb)(\w|=|\+|\/)*(?=[^\+=\w\/])/g, //encoding 5 time
  45. /(VmpGYVYySXhWWGROVldoVllURmFjRlJVUm5kV|VmpGYVYySXhWWGROVldoVllUSjRWbFpyV25kVW)(\w|=|\+|\/)*(?=[^\+=\w\/])/g, //encoding 6 time
  46. /(Vm1wR1lWWXlTWGhXV0dST1ZsZG9WbGxVUm1GalJsSlZVbTVrV|Vm1wR1lWWXlTWGhXV0dST1ZsZG9WbGxVU2pSV2JGcHlWMjVrVl)(\w|=|\+|\/)*(?=[^\+=\w\/])/g, //encoding 7 time
  47. /(Vm0xd1IxbFdXWGxUV0doWFYwZFNUMVpzWkc5V2JHeFZVbTFHYWxKc1NsWlZiVFZyV|Vm0xd1IxbFdXWGxUV0doWFYwZFNUMVpzWkc5V2JHeFZVMnBTVjJKR2NIbFdNalZyVm)(\w|=|\+|\/)*(?=[^\+=\w\/])/g, //encoding 8 time
  48. /(Vm0weGQxSXhiRmRYV0d4VVYwZG9XRll3WkZOVU1WcHpXa2M1VjJKSGVGWlZiVEZIWVd4S2MxTnNXbFppVkZaeV|Vm0weGQxSXhiRmRYV0d4VVYwZG9XRll3WkZOVU1WcHpXa2M1VjJKSGVGWlZNbkJUVmpKS1IyTkliRmROYWxaeVZt)(\w|=|\+|\/)*(?=[^\+=\w\/])/g, //encoding 9 time
  49. /(Vm0wd2VHUXhTWGhpUm1SWVYwZDRWVll3Wkc5WFJsbDNXa1pPVlUxV2NIcFhhMk0xVmpKS1NHVkdXbFppVkVaSVdWZDRTMk14VG5OWGJGcHBWa1phZ|Vm0wd2VHUXhTWGhpUm1SWVYwZDRWVll3Wkc5WFJsbDNXa1pPVlUxV2NIcFhhMk0xVmpKS1NHVkdXbFpOYmtKVVZtcEtTMUl5VGtsaVJtUk9ZV3hhZVZad)(\w|=|\+|\/)*(?=[^\+=\w\/])/g, //encoding 10 time
  50. /(Vm0wd2QyVkhVWGhUV0docFVtMVNXVll3WkRSV1ZsbDNXa2M1V0ZKc2JETlhhMXBQVmxVeFYyTkljRmhoTWsweFZtcEtTMU5IVmtkWGJGcHBWa1ZhU1ZkV1pEUlRNazE0Vkc1T1dHSkdjSEJXYTFwaF|Vm0wd2QyVkhVWGhUV0docFVtMVNXVll3WkRSV1ZsbDNXa2M1V0ZKc2JETlhhMXBQVmxVeFYyTkljRmhoTWsweFZtcEtTMU5IVmtkWGJGcE9ZbXRLVlZadGNFdFRNVWw1Vkd0c2FWSnRVazlaVjNoaFpWWmFk)(\w|=|\+|\/)*(?=[^\+=\w\/])/g, //encoding 11 time
  51. ];
  52.  
  53. //regex prefix - drag
  54. const regInvalid = /[^\w\+\/=]/;
  55.  
  56. //update chk, fail->false
  57. let updateAvailble = true;
  58.  
  59. //auto drag decoding enable status
  60. let draggableActivated = false;
  61.  
  62. //encoded link list, [uuid]: [encoded link]
  63. let encodedList = {};
  64.  
  65. //total decode count
  66. let hindex = 0;
  67.  
  68. //drag function comparison
  69. let lastSelected = document;
  70. let lastSelectedTime = Date.now();
  71.  
  72. //logging prefix, param
  73. const sc_name = '['+GM.info.script.name+']';
  74. const sc_name_upd = '['+GM.info.script.name+'-UPD]';
  75. const sc_name_par = '['+GM.info.script.name+'-PAR]';
  76.  
  77. //script menu parameter, user changeable
  78. let localParameter = {
  79. 'basedepth': {
  80. 'param_name': 'basedepth',
  81. 'name': 'base64 깊이 조절하기 - 현재 값 : 알수없음',
  82. 'desc': '자동 base64 디코딩 깊이를 조절할 수 있습니다.',
  83. 'id': -1,
  84. 'func': menucmd_f_depth,
  85. 'value': 3,
  86. 'def_value': 3,
  87. 'visible': true,
  88. },
  89. 'enclinkhide': {
  90. 'param_name': 'enclinkhide',
  91. 'name': '인코딩된 링크 [보이기/숨기기]',
  92. 'desc': '자동 base64 디코딩 전 인코딩된 링크 표시 여부를 설정할 수 있습니다.',
  93. 'id': -1,
  94. 'func': menucmd_f_enchide,
  95. 'value': false,
  96. 'def_value': true,
  97. 'visible': true,
  98. },
  99. 'draggable': {
  100. 'param_name': 'draggable',
  101. 'name': '드래그 시 자동 디코딩 [켜기/끄기]',
  102. 'desc': '드래그 시 자동으로 드래그한 부분을 base64로 디코딩할지 설정할 수 있습니다.',
  103. 'id': -1,
  104. 'func': menucmd_f_drag,
  105. 'value': false,
  106. 'def_value': false,
  107. 'visible': true,
  108. },
  109. 'updatechk': {
  110. 'param_name': 'chkupd',
  111. 'name': '업데이트 알림 [켜기/끄기]',
  112. 'desc': '새 버전이 나올 시 업데이트 확인 알림을 띄울지 여부를 설정할 수 있습니다.',
  113. 'id': -1,
  114. 'func': menucmd_f_updchk,
  115. 'value': true,
  116. 'def_value': true,
  117. 'visible': true,
  118. },
  119. };
  120.  
  121. //auto add padding - add '=' padding in base64 encoded string
  122. function base64AddPadding(str) {
  123. return str + Array((4 - str.length % 4) % 4 + 1).join('=');
  124. }
  125.  
  126. //base64 decode
  127. const Base64 = {
  128. _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  129. decode : function (input) {
  130. let output = "";
  131. let chr1, chr2, chr3;
  132. let enc1, enc2, enc3, enc4;
  133. let i = 0;
  134.  
  135. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  136.  
  137. while (i < input.length) {
  138. enc1 = this._keyStr.indexOf(input.charAt(i++));
  139. enc2 = this._keyStr.indexOf(input.charAt(i++));
  140. enc3 = this._keyStr.indexOf(input.charAt(i++));
  141. enc4 = this._keyStr.indexOf(input.charAt(i++));
  142.  
  143. chr1 = (enc1 << 2) | (enc2 >> 4);
  144. chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  145. chr3 = ((enc3 & 3) << 6) | enc4;
  146.  
  147. //last bits
  148. output = output + String.fromCharCode(chr1);
  149. if (enc3 != 64) { //=
  150. output = output + String.fromCharCode(chr2);
  151. }
  152. if (enc4 != 64) { //==
  153. output = output + String.fromCharCode(chr3);
  154. }
  155. }
  156.  
  157. output = Base64._utf8_decode(output);
  158. return output;
  159. },
  160. // private method for UTF-8 decoding
  161. _utf8_decode : function (utftext) {
  162. let string = "";
  163. let i = 0;
  164. let c = 0;
  165. let c1 = 0;
  166. let c2 = 0;
  167. let c3 = 0;
  168.  
  169. while ( i < utftext.length ) {
  170. c = utftext.charCodeAt(i);
  171. if (c < 128) {
  172. string += String.fromCharCode(c);
  173. i++;
  174. }
  175. else if((c > 191) && (c < 224)) {
  176. c2 = utftext.charCodeAt(i+1);
  177. string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
  178. i += 2;
  179. }
  180. else {
  181. c2 = utftext.charCodeAt(i+1);
  182. c3 = utftext.charCodeAt(i+2);
  183. string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
  184. i += 3;
  185. }
  186. }
  187. return string;
  188. }
  189. };
  190.  
  191. //encoded link click callback
  192. function showEncodedLink(event) {
  193. const self = event.currentTarget;
  194. //check already clicked
  195. if (encodedList.hasOwnProperty(self.id)) {
  196. console.log(sc_name,'show encoded link -',encodedList[self.id]);
  197. self.innerHTML = encodedList[self.id];
  198. self.style.color = 'rgb(71 88 188)';
  199. self.title = '디코딩 전 인코딩된 링크입니다.';
  200. //delete encodedList[self.id];
  201. }
  202. return;
  203. }
  204.  
  205. //link area
  206. function createEncodedLink(src) {
  207. return '<span style="font-size: 87.5%;color: rgb(71 188 115);">[ ' + src.toString() + ' ]</span>';
  208. }
  209.  
  210. //encoded link element
  211. function createMaskEncodedLink(src) {
  212. const uuid = 'abad_'+self.crypto.randomUUID();
  213. encodedList[uuid] = src;
  214. return '<span id="' + uuid.toString() + '" title="클릭 시 디코딩 전 인코딩된 링크를 표시합니다.">' + '클릭 시 인코딩된 코드 보기' + '</span>';
  215. }
  216.  
  217. //link creation
  218. function createLink(src, index, url, depth, hidelink = false) {
  219. //n번째 링크 (base64 깊이: 0) [ ABCDEF= / 클릭시 원본~ ]
  220. return '<a href="'+url+'" title="'+url+' (새 창으로 열기)" target="_blank" rel="external nofollow noopener noreferrer">'+index.toString()+'번째 링크 (base64 깊이: '+depth.toString()+')</a> '+(hidelink?createEncodedLink(createMaskEncodedLink(src)):createEncodedLink(src))+'';
  221. }
  222.  
  223. //decode & generate
  224. function replacerGen(numIter) {
  225. return function(source) {
  226. try {
  227. let rstring = ""; //return msg
  228. console.log('\n'+sc_name,'No.',(hindex+1),'encoded link:\n', source.toString()); //source
  229.  
  230. //decode
  231. let converted = Base64.decode(base64AddPadding(source));
  232. //attempt to decode nested base64 encoded string
  233. for(let i=0; i<numIter; i++) {
  234. converted = Base64.decode(base64AddPadding(converted));
  235. }
  236. hindex++;
  237.  
  238. //remove invalid string - �
  239. converted = decodeURI(encodeURI(converted).replaceAll('%00', ''));
  240. console.log(sc_name,'No.',hindex,'decode completed (depth:',numIter+1,'):\n',converted.toString()); //converted
  241.  
  242. //split by new line
  243. converted = converted.split(/\r?\n/);
  244. //single component
  245. if (converted.length == 2 && converted[converted.length-1] == '') {
  246. rstring += createLink(source, hindex, converted[0], numIter+1, !localParameter.enclinkhide.value);
  247. //multiple component
  248. } else if (converted.length > 1) {
  249. rstring += createEncodedLink(localParameter.enclinkhide.value?source.toString():createMaskEncodedLink(source.toString()));
  250.  
  251. let nindex = 1;
  252. const hindex_org = hindex;
  253. converted.forEach(function(i) {
  254. if (i != '') {
  255. rstring += '<br>' + createLink('<span style="color: rgb(71 188 115);" title="자동으로 분할된 '+nindex.toString()+'번째 링크입니다.">링크 자동 분할 : '+nindex.toString()+'번째</span>', hindex, i, numIter+1);
  256. hindex++;
  257. nindex++;
  258. }
  259. });
  260. //apply last components
  261. hindex--;
  262. nindex--;
  263.  
  264. console.log(sc_name,'No.',hindex_org,'- splitted total :', nindex);
  265. rstring = '<span style="color: rgb(232 62 140);"><b><i>분할된 링크 총 '+nindex.toString()+'개</i></b></span> ' + rstring;
  266. } else rstring += createLink(source, hindex, converted, numIter+1, !localParameter.enclinkhide.value);
  267. return rstring;
  268. } catch(e) {
  269. console.warn('\n'+sc_name,'error occured during decoding:', e);
  270. console.warn(sc_name,'base64 decode fail:', source);
  271. }
  272. return '<span style="color: rgb(255 0 0);">[ base64 변환 실패: '+source.toString()+' ]</span>';
  273. };
  274. }
  275.  
  276. //user drag event
  277. function selClicked(event) {
  278. const sel = document.getSelection().toString();
  279. if (!sel.match(regInvalid) && sel.length >= 10 && lastSelectedTime + 200 < Date.now()) {
  280. try {
  281. console.log(sc_name,'live match -',sel.toString());
  282. let converted = decodeURI(encodeURI(Base64.decode(base64AddPadding(sel))).replaceAll('%00', ''));
  283. console.log(sc_name,'converted -',converted.toString());
  284. this.innerHTML = this.innerHTML.replace(sel, converted)+' ';
  285. } catch (e) {
  286. return;
  287. } finally {
  288. this.removeEventListener('click', selClicked);
  289. }
  290. }
  291. }
  292.  
  293. //user drag activate
  294. function activateDragDecoding() {
  295. if(draggableActivated) {
  296. console.log(sc_name,'USR-Drag already enabled.');
  297. return;
  298. }
  299. draggableActivated = true;
  300. console.log(sc_name,'USR-Drag enabled.');
  301. document.addEventListener('selectionchange', function() {
  302. let sel = document.getSelection().anchorNode;
  303. if(sel) {
  304. sel = sel.parentElement;
  305. if(sel != lastSelected) {
  306. lastSelected.removeEventListener('click', selClicked);
  307. sel.addEventListener('click', selClicked);
  308. lastSelected = sel;
  309. lastSelectedTime = Date.now();
  310. }
  311. }
  312. });
  313. }
  314.  
  315. //update check
  316. function checkForUpdate(){
  317. if (!updateAvailble || !localParameter.updatechk.value) {
  318. console.log(sc_name_upd,'updchk skipped.');
  319. return;
  320. }
  321. console.log(sc_name_upd,'checking for update...');
  322. const tar_sc = 'https://update.greasyfork.org/scripts/482577/Arca%20base64%20autodecoder.user.js';
  323. fetch(tar_sc)
  324. .then(response => response.text())
  325. .then(data => {
  326. //extract version from greaskyfork script
  327. const match = data.match(/@version\s+(\d+\.\d+)/);
  328. if (match) {
  329. const tar_version = parseFloat(match[1]);
  330. const cur_version = parseFloat(GM.info.script.version);
  331. //new version detected
  332. if (tar_version > cur_version) {
  333. console.log(sc_name_upd,'new version available. ('+cur_version+' -> '+tar_version+')');
  334. //y/n dialog
  335. if (window.confirm(sc_name+'\n새로운 버전이 감지되었습니다. 업데이트를 권장합니다.\n( 기존버전 : '+cur_version+', 새로운 버전 : '+tar_version+' )\n(변경사항은 아카라이브 게시글을 참고해주세요.)\n\n취소를 누르면 앞으로 업데이트 알림을 띄우지 않습니다.')) {
  336. //get extension env
  337. if(!GM.info.scriptWillUpdate) {
  338. console.log(sc_name_upd,'extension not allowed auto update..');
  339. if (window.confirm(sc_name+'\n주의! 스크립트 내용 변경 등으로 인해 확장프로그램 내 자동 업데이트가 꺼져있는 것 같습니다.\n업데이트 시 기존 스크립트에 덮어쓰게 되어 기존 내용이 손실될 수 있습니다.\n이 점 확인 후 업데이트 바랍니다.\n\n(계속하려면 확인, 취소하려면 취소를 눌러주세요.)')) {
  340. console.log(sc_name_upd,'opening source url..');
  341. window.location.replace(tar_sc);
  342. window.alert(sc_name+'\n업데이트 후 새로고침해야 적용됩니다.');
  343. } else {
  344. console.log(sc_name_upd,"user canceled.");
  345. }
  346. } else {
  347. console.log(sc_name_upd,'opening source url..');
  348. window.location.replace(tar_sc);
  349. window.alert(sc_name+'\n업데이트 후 새로고침해야 적용됩니다.');
  350. }
  351. } else {
  352. console.log(sc_name_par,'updatechk change',true.toString(),'to',false.toString());
  353. localParameter.updatechk.value = false;
  354. try {
  355. GM.setValue('chkupd', false);
  356. console.log(sc_name_par,"updatechk change successful");
  357. menucmd_update();
  358. window.alert(sc_name+'\n앞으로 업데이트 알림을 띄우지 않습니다.');
  359. } catch(e) {
  360. localParameter.updatechk.value = true;
  361. console.error(sc_name_par,"updatechk change fail -", e);
  362. window.alert(sc_name+'\n파라미터 변경 중 문제 발생, 로그를 확인해주세요..');
  363. }
  364. }
  365. } else {
  366. console.log(sc_name_upd,'latest version', cur_version, 'detected. (eth:',tar_version,')');
  367. }
  368. } else {
  369. console.error(sc_name_upd,'unable to extract version..');
  370. }
  371. })
  372. .catch(error => {
  373. updateAvailble = false;
  374. console.error(sc_name_upd,'link unreachable.. -', error);
  375. });
  376. updateAvailble = false;
  377. }
  378.  
  379. function menucmd_update(fist_run = false) {
  380. //pre process
  381. localParameter.basedepth.value = localParameter.basedepth.value > regArr.length ? regArr.length : localParameter.basedepth.value;
  382.  
  383. //update menu name
  384. localParameter.basedepth.name = 'base64 깊이 조절하기 - 현재 값 : '+localParameter.basedepth.value+'회';
  385. localParameter.enclinkhide.name = '인코딩된 링크 '+(localParameter.enclinkhide.value?'숨기기':'보이기');
  386. localParameter.draggable.name = '드래그 시 자동 디코딩 '+(localParameter.draggable.value?'끄기':'켜기');
  387. localParameter.updatechk.name = '업데이트 알림 '+(localParameter.updatechk.value?'끄기':'켜기');
  388.  
  389. //remove exist menu cmd
  390. if (!fist_run) {
  391. Object.keys(localParameter).forEach(function(i){
  392. try {
  393. GM.unregisterMenuCommand(localParameter[i].id);
  394. } catch(_) {}
  395. });
  396. }
  397. //monkey menu cmd register
  398. try {
  399. Object.keys(localParameter).forEach(function(i){
  400. if (localParameter[i].visible) {
  401. localParameter[i].id = GM.registerMenuCommand(localParameter[i].name, localParameter[i].func, {title:localParameter[i].desc});
  402. } else {
  403. localParameter[i].value = localParameter[i].def_value;
  404. }
  405. });
  406. console.log(sc_name_par,'ext opt pannel',(fist_run?'registered':'reloaded'));
  407. } catch(e) {
  408. console.error(sc_name_par,'err - ext opt pannel',(fist_run?'register':'reload'),'- ', e);
  409. Object.keys(localParameter).forEach(function(i){
  410. try {
  411. GM.unregisterMenuCommand(localParameter[i].id);
  412. } catch(_) {}
  413. });
  414. }
  415. }
  416.  
  417. function menucmd_f_depth() {
  418. menucmd_update();
  419. const prev_value = localParameter.basedepth.value;
  420. const str_common_1 = ' ( 지정 가능한 범위: 1~'+regArr.length.toString()+' )';
  421. while(true) {
  422. const input = window.prompt(sc_name+'\nBase64 자동 디코딩 중첩 횟수를 얼마로 지정할까요?\n(인코딩을 인코딩한 것을 여러번 반복한걸 자동으로 풀어냅니다.)\n현재 값: '+prev_value.toString()+'회,'+(prev_value == 3 ? '' : ' 기본값: 3회,')+str_common_1+'\n\n(값을 너무 크게 지정하면 컴퓨터 성능에 영향을 줄 수 있습니다.)', prev_value);
  423. if (input == null) {
  424. console.log(sc_name,'basedepth change canceled.');
  425. break;
  426. }
  427. if(!isNaN(input)){
  428. const tar_value = parseInt(input);
  429. if(tar_value == prev_value) {
  430. window.alert(sc_name+'\n동일한 값을 입력했습니다, 현재 값: '+prev_value+'회');
  431. } else if(tar_value >= 1 && tar_value <= regArr.length) {
  432. console.log(sc_name_par,'basedepth change',prev_value.toString(),'to',tar_value.toString());
  433. localParameter.basedepth.value = tar_value;
  434. try {
  435. GM.setValue('basedepth', tar_value);
  436. console.log(sc_name_par,"basedepth change successful");
  437. window.alert(sc_name+'\n값이 '+prev_value.toString()+'에서 '+tar_value.toString()+'으로 변경이 완료되었습니다.\n\n(사이트를 새로고침해야 반영됩니다.)');
  438. } catch(e) {
  439. localParameter.basedepth.value = prev_value;
  440. console.error(sc_name_par,"basedepth change fail -", e);
  441. window.alert(sc_name+'\n파라미터 변경 중 문제 발생, 로그를 확인해주세요..');
  442. } finally {
  443. menucmd_update();
  444. }
  445. break;
  446. } else {
  447. window.alert(sc_name+'\n'+tar_value+'(으)로 설정할 수 없습니다.\n범위를 초과하였습니다..'+str_common_1);
  448. }
  449. } else {
  450. window.alert(sc_name+'\n'+input+'은(는)숫자가 아닙니다.\n숫자만 입력해주세요..'+str_common_1);
  451. }
  452. }
  453. }
  454.  
  455. function menucmd_f_enchide() {
  456. menucmd_update();
  457. const curr_state = localParameter.enclinkhide.value;
  458. if(window.confirm(sc_name+'\n디코딩 시 인코딩된 링크를 '+(curr_state?'숨기시':'표시하')+'겠습니까?\n\n(앞으로 디코딩 전 인코딩된 링크를\n"'+(curr_state?'클릭 시 기존링크 보기':'aHR0cHM6Ly9hcmNhLmx..')+'"와 같은 형태로 보여줍니다.)')) {
  459. const set_state = !curr_state;
  460. console.log(sc_name_par,'enchide change',curr_state.toString(),'to',set_state.toString());
  461. localParameter.enclinkhide.value = set_state;
  462. try {
  463. GM.setValue('enclinkhide', set_state);
  464. console.log(sc_name_par,"updatechk change successful");
  465. if(set_state) {
  466. window.alert(sc_name+'\n앞으로 인코딩된 링크를 표시합니다.\n\n(새로고침해야 적용됩니다.)');
  467. } else {
  468. window.alert(sc_name+'\n앞으로 인코딩된 링크를 숨깁니다.');
  469. }
  470. } catch(e) {
  471. localParameter.enclinkhide.value = curr_state;
  472. console.error(sc_name_par,"enchide change fail -", e);
  473. window.alert(sc_name+'\n파라미터 변경 중 문제 발생, 로그를 확인해주세요..');
  474. } finally {
  475. menucmd_update();
  476. }
  477. } else {
  478. console.log(sc_name,'enchide change canceled.');
  479. }
  480. }
  481.  
  482. function menucmd_f_drag() {
  483. menucmd_update();
  484. const curr_state = localParameter.draggable.value;
  485. if(window.confirm(sc_name+'\n드래그 시 자동 디코딩을 '+(curr_state?'비':'')+'활성화 하시겠습니까?\n\n(앞으로 인코딩된 부분을 드래그'+(curr_state?'해도 자동으로 디코딩되지 않습':' 시 Base64로 인코딩된것으로\n판단 되면 자동으로 디코딩을 시도합')+'니다.)\n\n(이 기능은 작동이 불안정할 수 있습니다.)')) {
  486. const set_state = !curr_state;
  487. console.log(sc_name_par,'draggable change',curr_state.toString(),'to',set_state.toString());
  488. localParameter.draggable.value = set_state;
  489. try {
  490. GM.setValue('draggable', set_state);
  491. console.log(sc_name_par,"draggable change successful");
  492. if(set_state) {
  493. try {
  494. activateDragDecoding();
  495. window.alert(sc_name+'\n앞으로 드래그 시 자동 디코딩을 진행합니다.');
  496. } catch(e) {
  497. console.error(sc_name,"draggable activate fail -", e);
  498. window.alert(sc_name+'\n드래그 시 자동 디코딩 활성화 중 문제가 발생했습니다.\n새로고침이 필요합니다..');
  499. }
  500. } else {
  501. window.alert(sc_name+'\n앞으로 드래그 해도 반응하지 않습니다.\n\n(새로고침해야 적용됩니다.)');
  502. }
  503. } catch(e) {
  504. localParameter.draggable.value = curr_state;
  505. console.error(sc_name_par,"draggable change fail -", e);
  506. window.alert(sc_name+'\n파라미터 변경 중 문제 발생, 로그를 확인해주세요..');
  507. } finally {
  508. menucmd_update();
  509. }
  510. } else {
  511. console.log(sc_name,'draggable change canceled.');
  512. }
  513. }
  514.  
  515. function menucmd_f_updchk() {
  516. menucmd_update();
  517. const curr_state = localParameter.updatechk.value;
  518. if(window.confirm(sc_name+'\n업데이트 알림을 '+(curr_state?'끄':'켜')+'시겠습니까?\n\n(앞으로 업데이트가 있'+(curr_state?'어도 알려주지 않습':'으면 자동으로 알려줍')+'니다.)')) {
  519. const set_state = !curr_state;
  520. console.log(sc_name_par,'updatechk change',curr_state.toString(),'to',set_state.toString());
  521. localParameter.updatechk.value = set_state;
  522. try {
  523. GM.setValue('chkupd', set_state);
  524. console.log(sc_name_par,"updatechk change successful");
  525. if(set_state) {
  526. window.alert(sc_name+'\n앞으로 업데이트가 존재하면 알림을 띄웁니다.');
  527. } else {
  528. window.alert(sc_name+'\n앞으로 업데이트 알림을 띄우지 않습니다.');
  529. }
  530. } catch(e) {
  531. localParameter.updatechk.value = curr_state;
  532. console.error(sc_name_par,"updatechk change fail -", e);
  533. window.alert(sc_name+'\n파라미터 변경 중 문제 발생, 로그를 확인해주세요..');
  534. } finally {
  535. menucmd_update();
  536. }
  537. } else {
  538. console.log(sc_name,'updatechk change canceled.');
  539. }
  540. }
  541.  
  542. //main
  543. (async () => {
  544. 'use strict';
  545.  
  546. //chk browser env
  547. if (((navigator.language || navigator.userLanguage) != 'ko-KR')) console.warn('Warning! this script support only korean language..');
  548.  
  549. let url_tail = location.href.match(/([/][a-z0-9_-]*[\/]?)$/g);
  550. if(url_tail != null) {
  551. if(url_tail[0] == '/edit') {
  552. console.log(sc_name,'edit mode detected, function disabled.');
  553. try {GM.registerMenuCommand("Edit 모드에서는 작동하지 않음", ()=>{window.alert(sc_name+'\n작성 또는 수정모드에서는 작동하지 않습니다..');});} catch(_) {}
  554. return;
  555. }
  556. }
  557.  
  558. console.log(sc_name,'V',GM.info.script.version,'enabled');
  559.  
  560. //load parameter
  561. try {
  562. for (const i of Object.keys(localParameter)) {
  563. localParameter[i].value = await GM.getValue(localParameter[i].param_name, localParameter[i].value);
  564. }
  565. console.log(sc_name_par, 'parameter load successful.');
  566. } catch(e) {
  567. console.error(sc_name_par,'err - get sc parameter - ', e);
  568. }
  569.  
  570. //apply parameter and register monkey menu command
  571. menucmd_update(true);
  572.  
  573. //chk update
  574. await checkForUpdate();
  575.  
  576. //drag auto decoding
  577. if (localParameter.draggable.value) {
  578. activateDragDecoding();
  579. }
  580.  
  581. console.log(sc_name,'ready');
  582. //main procedure
  583.  
  584. //article
  585. let article = document.getElementsByClassName("article-content")[0];
  586. if (article != undefined) {
  587. for(let i=0; i<localParameter.basedepth.value; i++) {
  588. article.innerHTML = article.innerHTML.replaceAll(regArr[i], replacerGen(i));
  589. }
  590. } else console.warn(sc_name,'no article detected.');
  591.  
  592. //comment
  593. let comments = document.getElementsByClassName("list-area");
  594. if (article != undefined) {
  595. if (comments.length != 0) {
  596. for(let i=0; i<localParameter.basedepth.value; i++) {
  597. comments[0].innerHTML = comments[0].innerHTML.replaceAll(regArr[i], replacerGen(i));
  598. }
  599. }
  600. } else console.warn(sc_name,'no comments detected.');
  601. console.log(sc_name,'total',hindex,'link decode task completed.');
  602.  
  603. //add eventlistner - click, show original encoded link
  604. if (!localParameter.enclinkhide.value) {
  605. Object.keys(encodedList).forEach(function(i) {
  606. document.getElementById(i).addEventListener('click', showEncodedLink, { once : true } );
  607. });
  608. }
  609. })();