Advertisement
Guest User

Untitled

a guest
Aug 31st, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. // ==UserScript==
  2. // @name チャンネル追加作業支援スクリプト
  3. // @namespace https://www65.atwiki.jp/operationobihiro/
  4. // @version 0.8
  5. // @description 編集画面に簡易入力欄が出るで バグまみれ注意
  6. // @author Mr.K
  7. // @match https://www65.atwiki.jp/operationobihiro/*
  8. // @match http://www65.atwiki.jp/operationobihiro/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. //入力をテンプレートに加工
  16. function generateTemplate(channel_info){
  17. //改行で分割
  18. var channel_infos = channel_info.split(/\n/);
  19. //リンク部分を切り出し
  20. var link = channel_infos.slice(0,3);
  21. channel_infos.splice(0,3);
  22. //数字を3文字ごとにコンマ打つ
  23. channel_infos.forEach(function (value, index){
  24. channel_infos[index] = value.replace(/^(\d+)(\d{3})/g, '$1,$2');
  25. })
  26. //リンク部生成
  27. var template = '|[[' + link[0] + '.' + link[1] + '>' + link[2] + ']]';
  28. //残りを生成
  29. channel_infos.forEach(function (value){
  30. template = template + '|' + value;
  31. });
  32. template = template + '|';
  33.  
  34. return template;
  35.  
  36. }
  37.  
  38. //入力欄挿入
  39. var edit = document.getElementById('atwiki_tags_edit');
  40. edit.insertAdjacentHTML('beforeBegin', '<div id="channel_edit">チャンネル情報の区切りは改行で 一行あけて複数チャンネル追加<br>例:<br>1<br>ガアラCh<br>https://www.youtube.com/channel/UCF_xjdswdp3Xf3kJtSUsmHw<br>19046<br>457<br>5/18<br><br>46<br>Patriot J<br>https://www.youtube.com/channel/UCdz9MFk91aledHUOzy8Rb0Q<br>3226<br>396<br>ポ<textarea name="tags" id="channel_edit_form" value="" style="width:100%" rows="10"></textarea><br>入力したら下のボタンをポチーで<br><input type="button" id="channel_edit_button" value="テンプレート出力"></div>');
  41.     var form = document.getElementById('channel_edit_form');
  42. var button = document.getElementById('channel_edit_button');
  43. var listReg = /\|(?!\n\|)(?=\n)/g;
  44. var list;
  45. var lists = [];
  46. while ((list = listReg.exec(document.getElementById('tarea_wiki').value)) !== null){
  47. lists.push(list.index);
  48. }
  49. console.log(lists)
  50. /*document.getElementById('tarea_wiki').style.lineHeight = '20px';
  51.  
  52. var fontsize = window.getComputedStyle(document.getElementById('channel_edit_form')).fontSize.replace( 'px' , '' );
  53. fontsize = Math.floor(fontsize * 10)/10;
  54. var scroll = (20 - fontsize) + fontsize ;
  55.  
  56. document.getElementsByClassName('tarea_wiki')[0].scrollTop = scroll * 10 + 10;*/
  57.  
  58.  
  59.  
  60.  
  61.  
  62. //ボタン押下で発火
  63. button.addEventListener('click', function() {
  64. var channel_info_array = form.value.split(/\n{2,}/).filter(function(a){
  65. return a !== ""
  66. });
  67. var templates = "";
  68. channel_info_array.forEach(function(value){
  69. templates = templates + generateTemplate(value) + "\n";
  70. });
  71. //形式が正しいかチェック
  72. if(templates.match(/https?:\/{2}www\.youtube\.com\/channel\/\S{24}(?!]])/)){
  73. //エラー
  74. button.insertAdjacentHTML('beforeBegin', '<div id="error">なんか間違っとるで</div>');
  75. }else{
  76. //以前に表示したエラーを非表示
  77. if(document.getElementById('error')){document.getElementById('error').parentNode.removeChild(document.getElementById('error'))}
  78. //入力欄に結果を表示
  79. form.value = templates;
  80. }
  81.  
  82. }, false);
  83.  
  84. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement