yama
https://pbs.twimg.com/profile_images/986113842739478528/2PlaIAsz_400x400.jpg
Personal
Name
yama
GitHub
Twitter
Qiita
はてなブログ
Hobby
作詞作曲,DTM
ギター
登山
マラソン
Product
Flaskで作成したアプリケーション
(2020年8月20日更新)
UserScript
2021/11/2 追記
めんどくさいことが多かったりしたので、一旦無くしました。使いたい時に選択できるようにしたいです。
code:script_dummy.js
import '/api/code/customize/web_pageをscrapbox記法に変換して貼り付けるUserScript/script.js'
code:script.js
import '/api/code/sukesan1984/選択範囲のsumを計算するやつ/script.js';
code:script.js
const __bkmClass = '.deco-\\.' /* ここで記法のセレクタを設定してね。デフォルトはドットです */
const __bkmMenuTitle = 'Bookmarks'
scrapbox.PageMenu.addMenu({ title: __bkmMenuTitle, image: '/assets/img/logo.png',
onClick: function() {
const __fixedHeaderHeight = ($('.navbar').css('position') == 'fixed' ? $('.navbar').height() : 0) +
($('.navbar-pagemenu').height() || 0)
scrapbox.PageMenu(__bkmMenuTitle).removeAllItems()
$(__bkmClass).closest('.line').each(function(i, e){
scrapbox.PageMenu(__bkmMenuTitle).addItem({
title: $(e).find(__bkmClass).text(),
onClick: function() {
$('html,body').animate({
scrollTop: $(e).offset().top - $('body').offset().top - __fixedHeaderHeight
}, 150)
}
})
})
}
})
code:script.js
scrapbox.TimeStamp.addFormat('#YYYY年M月D日')
code:script.js
import('/api/code/ci7lus/pdfの全てのページをGyazoにアップロードしてScrapboxに貼り付けるUserScript/script.js');
code:style.css
a#upload-pdf.tool-btn:hover {
text-decoration: none;
}
a#upload-pdf.tool-btn::before {
position: absolute;
left: calc(46px / 3 - 1px);
content: "\f1c1";
font: 21px/46px "Font Awesome 5 Free";
}
a#upload-pdf.tool-btn img {
opacity: 0;
}
code:throttle.js
/*
MIT License
Copyright (c) 2016 Dirk-Jan Wassink
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define("exports",n):n((e=e||self).throttle={})}(this,function(e){"use strict";var n={maxInProgress:5,failFast:!1,nextCheck:function(e,n){return Promise.resolve(e.amountStarted<n.length)},ignoreIsFunctionCheck:!1};function t(e,t){return new Promise(function(o,s){var c=Object.assign({},n,t),f={amountDone:0,amountStarted:0,amountResolved:0,amountRejected:0,amountNextCheckFalsey:0,rejectedIndexes:[],resolvedIndexes:[],nextCheckFalseyIndexes:[],taskResults:[]};if(0===e.length)return o(f);for(var u=!1,a=0,i=function(){if(!0!==u){if(f.amountDone++,"function"==typeof c.progressCallback&&c.progressCallback(f),f.amountDone===e.length)return o(f);a<e.length&&r(a++)}},r=function(n){c.nextCheck(f,e).then(function(t){!0===t?function(n){if(f.amountStarted++,"function"==typeof en)en().then(function(e){f.taskResultsn=e,f.resolvedIndexes.push(n),f.amountResolved++,i()},function(e){if(f.taskResultsn=e,f.rejectedIndexes.push(n),f.amountRejected++,!0===c.failFast)return u=!0,s(f);i()});else{if(!0!==c.ignoreIsFunctionCheck)return u=!0,s(new Error("tasks"+n+": "+en+", is supposed to be of type function"));f.taskResultsn=en,f.resolvedIndexes.push(n),f.amountResolved++,i()}}(n):(f.amountNextCheckFalsey++,f.nextCheckFalseyIndexes.push(n),i())},s)},h=0;h<Math.min(c.maxInProgress,e.length);h++)r(a++)})}function o(e,n){return new Promise(function(o,s){t(e,n).then(function(e){o(e.taskResults)},function(e){e instanceof Error?s(e):s(e.taskResults[e.rejectedIndexes0])})})}e.raw=t,e.sync=function(e,n){return o(e,Object.assign({},{maxInProgress:1,failFast:!0},n))},e.all=function(e,n){return o(e,Object.assign({},{failFast:!0},n))},Object.defineProperty(e,"__esModule",{value:!0})}); code:script.js
scrapbox.PopupMenu.addButton({
title: function (text) {
const chars = text.replace(/\r\n/g, '').length const words = text.trim().split(/\r\n\s+/).length return ${chars}c ${words}w
},
onClick: () => null
})
code:script.js
$('body').attr('data-daiiz-rel-bubble', 'on'); // 関連ページを吹き出し表示する
$('body').attr('data-daiiz-text-bubble', 'on'); // リンク先ページのテキストを表示する
$('body').attr('data-daiiz-icon-button', 'on'); // アイコンをボタンにする
$('body').attr('data-daiiz-paste-url-title', 'ctrl'); // URL titleの形でペーストする code:script.js
var $appRoot = $('#app-container')
var iconName = $icon.attr('title');
if(iconName === 'hello-world'){
alert('Hello World!');
// 親要素のaタグを無効化
return false;
};
})
code:script.js
import '/api/code/shokai/音声入力Menu/script.js'
code:script.js
scrapbox.PageMenu.addItem({
title: 'Open notepad',
onClick: () => window.open(/kyoyo-ds-2018-041/Note, '', 'location=no, width=488, height=668')
})
code:script.js
import '/api/code/daiiz/Open_Gyazo/script.js'
import '/api/code/daiiz/miilClient-button/script.js'
// import '/api/code/daiiz/Open_notepad/script.js'
import '/api/code/daiiz/ランダムページ/script.js'
import '/api/code/daiiz/ページの見出しを作るUserScript/script.js'
import '/api/code/daiiz/🔍 Google/script.js'
import '/api/code/daiiz/🔍 Scrapbox/script.js'
import '/api/code/shokai/Tweet_Menu/script.js'
import '/api/code/daiiz/omakase-links/script.js'
import '/api/code/daiiz/新書モード/script.js'
code:script.js
document.querySelector('.app')
.insertAdjacentHTML('beforeend', '<div id="presentation-progress" style="display:none"></div>')
document.querySelector('.app')
.insertAdjacentHTML('beforeend', `<style media="screen">
display: block !important;
z-index: 100; position: fixed; bottom: 0; left: 0; width: 100vw;
text-align: center; line-height: 1;
font-size: x-small; /* 📝バーの高さを変えたいときはフォントサイズを変えてね */
--bar-bgcolor: #eee; /* 📝プログレスバーの背景色 */ --complete: 0;
background: linear-gradient(to right,
var(--bar-color) var(--complete), var(--bar-bgcolor) var(--complete), var(--bar-bgcolor))
}
</style>`);
(() => {
const updateProgress = () => {
const sections = Array.from(document.querySelectorAll('.section-title'))
const currentPos = sections.findIndex(e => {
return window.getComputedStyle(e, null).getPropertyValue('display') != 'none'
}) + 1
const complete = currentPos / sections.length * 100
const progressBarElem = document.getElementById('presentation-progress')
progressBarElem.style.setProperty('--complete', complete + '%')
progressBarElem.innerText = ${currentPos} / ${sections.length}
}
const appObserver = new MutationObserver(mutations => {
mutations.forEach(mutation => {
const addedStyles = Array.from(mutation.addedNodes).filter(node => node.tagName == 'STYLE')
if (addedStyles.length) {
// プレゼンモード開始?
// STYLEタグも MutationObserver で監視したかったけど無理ぽいのでキーイベント拾います
window.addEventListener('keydown', updateProgress)
updateProgress()
}
const removedStyles = Array.from(mutation.removedNodes).filter(node => node.tagName == 'STYLE')
if (removedStyles.length) {
// プレゼンモード終了?
window.removeEventListener('keydown', updateProgress)
}
})
})
appObserver.observe(document.querySelector('.app'), { childList: true })
})()
code:script.js
$('body').attr('data-daiiz-icon-button', 'on');
$('body').attr('data-daiiz-rel-bubble', 'on');
$('body').attr('data-daiiz-text-bubble', 'on');
$('body').attr('data-daiiz-paste-url-title', 'ctrl');
code:script.js
// scrapbox.TimeStamp.addFormat("[[]YYYY年M月[]D日] HH時MM分")
//scrapbox.TimeStamp.addFormat("#YYYY年 #M月") 選択した文字列から新しいページを作成できる
code:script.js
// import '/api/code/shokai/ページの1部分を別のページに切り出すUserScript/script.js'`
Markdownに変換するボタン
code:script.js
function main(){var m=function(b){b=b.replace(/&/g,"&");b=b.replace(/</g,"<");b=b.replace(/>/g,">");b=b.replace(/"/g,""");return b=b.replace(/'/g,"'")},n=function(b){b=void 0===b?0:b;for(var a="",g=1;g<b;g++)a+=" ";return a},p=function(b){b=void 0===b?"":b;var a=document.createElement("div");a.innerHTML=b;b=a.querySelectorAll("strong");for(var g=0;g<b.length;g++){for(var c=bg,e=+c.className.split("level-")1,d=c.innerHTML,e=void 0===e?1:e,e=6-e,f="",h=0;h<e;h++)f+="#";c.innerHTML= f+" "+d}return a.innerHTML},q=function(b){b=void 0===b?"":b;var a=document.createElement("div");a.innerHTML=b;b=a.querySelectorAll("a");for(var g=0;g<b.length;g++){var c=bg,e=c.innerText.trim(),d=c.href,e=""+e+"("+d+")",f=c.querySelector("img");null!==f&&(e="[!Image("+f.src+")]("+d+")");c.innerText=e}return a.innerText},f=document.querySelector(".lines"),r=f.querySelector(".line-title .text").innerText,f=f.querySelectorAll(".line");var pageTexts=[];for(var l=1;l<f.length;l++){for(var d=fl.querySelector(".text").cloneNode(!0), h=d.querySelectorAll("span.empty-char-index"),a=0;a<h.length;a++){var k=ha;k.innerText=""}h=d.querySelectorAll("span.backquote");for(a=0;a<h.length;a++)k=ha,k.innerText="`";a=d.innerHTML.replace(/<span>/g,"");a=a.replace(/<span.+?>/g,"").replace(/<\/span>/g,"");a=a.replace(/<br.+?>/g,"");a=a.replace(/\n/gi,"").replace(/\t/gi,"").trim();a=p(a);a=q(a);d=d.querySelector(".indent-mark");null!==d&&(k=+d.style.width.split("em")0/1.5,a=n(k)+"- "+a);null===d&&0<a.length&&"#"!==a0&&(a+="<br>");pageTexts.push(a)}(function(b, a){b=void 0===b?"Title":b;a=void 0===a?[]:a;for(var d="# "+b+"\n",c=0;c<a.length;c++)d+="\n"+ac;print(m(d))} )(r,pageTexts)}; const print = body => {
const url = URL.createObjectURL(new Blob(bom, body, { type: "text/plain",
}))
window.open(url)
}
code:script.js
scrapbox.PopupMenu.addButton({
title : 'Embed Tweet',
onClick : text => {
const convertContent = (content, indent) => {
const replaced = content
.replace(/<a href="(https?:.*?)">(.*?)<\/a>/g, '$1 $2') .replace(/<br>/g, \n${indent});
const elem = document.createElement('div');
elem.innerHTML = replaced;
return indent + elem.innerText;
}
const tweetRegex = /(?<spaces>\t *)<blockquote\w"\-= *><p\w"\-= *>(?<content>.*)<\/p>—(?<author>.*)(?<link><a.*>)<\/blockquote>\n\t *<script.*?><\/script>/; const match = text.match(tweetRegex);
if(!match) return;
const {spaces, content, author, link} = match.groups;
const ind = ${spaces}>;
return text.replace(tweetRegex, convertContent(content, ind) + '\n' + convertContent(\t—${author} ${link}, ind));
}
})
code:script.js
scrapbox.PageMenu.addMenu({
title: '暗記シート',
});
scrapbox.PageMenu(暗記シート).addItem({
title: () => '赤文字を隠す',
});
scrapbox.PageMenu(暗記シート).addItem({
title: () => '赤文字を表示する',
})
動かない?
code:script.js
var daiizPageCounter = function () {
var dLog = {
'page': 0,
'theme': 'default',
'project': ''
};
var $p = $('div.page-list-status-bar');
$p.on('click', function (e) {
var $t = $(e.target).closest('div.page-list-status-bar');
dLog.page = +$t.text().match(/\d+/)0; dLog.project = $('#app-container').find('.navbar-brand > .title').text();
$.ajax({
'method': 'POST',
'dataType': 'json',
'data': JSON.stringify(dLog)
}).done(function (data) {});
});
var $links = $('link');
for (var i = 0; i < $links.length; i++) {
if (href.match(/\/themes\//) !== null) {
dLog.theme = href.split('/themes/')1.split('.css')0; break;
}
}
$p.css({cursor: 'pointer'});
};
window.setTimeout(daiizPageCounter, 1000 * 3);