Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name チャンネル追加作業支援スクリプト
- // @namespace https://www65.atwiki.jp/operationobihiro/
- // @version 0.8
- // @description 編集画面に簡易入力欄が出るで バグまみれ注意
- // @author Mr.K
- // @match https://www65.atwiki.jp/operationobihiro/*
- // @match http://www65.atwiki.jp/operationobihiro/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- //入力をテンプレートに加工
- function generateTemplate(channel_info){
- //改行で分割
- var channel_infos = channel_info.split(/\n/);
- //リンク部分を切り出し
- var link = channel_infos.slice(0,3);
- channel_infos.splice(0,3);
- //数字を3文字ごとにコンマ打つ
- channel_infos.forEach(function (value, index){
- channel_infos[index] = value.replace(/^(\d+)(\d{3})/g, '$1,$2');
- })
- //リンク部生成
- var template = '|[[' + link[0] + '.' + link[1] + '>' + link[2] + ']]';
- //残りを生成
- channel_infos.forEach(function (value){
- template = template + '|' + value;
- });
- template = template + '|';
- return template;
- }
- //入力欄挿入
- var edit = document.getElementById('atwiki_tags_edit');
- 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>');
- var form = document.getElementById('channel_edit_form');
- var button = document.getElementById('channel_edit_button');
- var listReg = /\|(?!\n\|)(?=\n)/g;
- var list;
- var lists = [];
- while ((list = listReg.exec(document.getElementById('tarea_wiki').value)) !== null){
- lists.push(list.index);
- }
- console.log(lists)
- /*document.getElementById('tarea_wiki').style.lineHeight = '20px';
- var fontsize = window.getComputedStyle(document.getElementById('channel_edit_form')).fontSize.replace( 'px' , '' );
- fontsize = Math.floor(fontsize * 10)/10;
- var scroll = (20 - fontsize) + fontsize ;
- document.getElementsByClassName('tarea_wiki')[0].scrollTop = scroll * 10 + 10;*/
- //ボタン押下で発火
- button.addEventListener('click', function() {
- var channel_info_array = form.value.split(/\n{2,}/).filter(function(a){
- return a !== ""
- });
- var templates = "";
- channel_info_array.forEach(function(value){
- templates = templates + generateTemplate(value) + "\n";
- });
- //形式が正しいかチェック
- if(templates.match(/https?:\/{2}www\.youtube\.com\/channel\/\S{24}(?!]])/)){
- //エラー
- button.insertAdjacentHTML('beforeBegin', '<div id="error">なんか間違っとるで</div>');
- }else{
- //以前に表示したエラーを非表示
- if(document.getElementById('error')){document.getElementById('error').parentNode.removeChild(document.getElementById('error'))}
- //入力欄に結果を表示
- form.value = templates;
- }
- }, false);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement