teratail 修正依頼を定型文で送る
by
Lhankor_Mhy
2020-01-10 [2020/01/10 18:24:55]
https://teratail.com/questions/233570 からインスパイア。
@@ -10,43 +10,53 @@
void (async()=>{
+ const $id = document.getElementById.bind(document);
const $qs = ( s, c = document ) => {
const r = Array.from( c.querySelectorAll(s) );
return r.length ? r : [document.createDocumentFragment()];
};
- const helpHTML = ( new DOMParser() ).parseFromString(
- await(await fetch("https://teratail.com/help/question-tips")).text(),
- 'text/html'
- );
- const helpDOM = $qs( '.P-navigation', helpHTML )[0];
-
- const div = document.createElement('div');
- div.style.position = 'fixed';
- div.style.top = '0';
- div.style.width = '50vw';
- div.style.height = '100vh';
- div.style.background = 'rgba(255,255,255,0.5)';
- div.style.zIndex = '99';
- div.appendChild(helpDOM);
-
- const backDiv = document.createElement('div');
- backDiv.style.position = 'fixed';
- backDiv.style.top = '0';
- backDiv.style.width = '100vw';
- backDiv.style.height = '100vh';
- backDiv.style.zIndex = '98';
-
- document.body.appendChild(backDiv);
- document.body.appendChild(div);
-
- helpDOM.addEventListener('click',e=>{
- $qs('#RequestRewriteInfoForm')[0].value += e.target.textContent + "\nhttps://teratail.com/help/question-tips" + e.target.getAttribute('href') + '\n\n';
- });
-
- backDiv.addEventListener('click',e=>{
- backDiv.remove();
- div.remove();
- });
+ const url = "https://teratail.com/help/question-tips";
+ const helpTagName = '.P-navigation';
+ const wrapperTagName = 'g5G38emWp5UZ';
+
+ if ( $id( wrapperTagName ) ){
+ $id( wrapperTagName ).style.display = 'block';
+ } else {
+ const helpHTML = ( new DOMParser() ).parseFromString(
+ await(await fetch(url)).text(),
+ 'text/html'
+ );
+
+ const div = document.createElement('div');
+ div.id = wrapperTagName;
+
+ const helpDOM = $qs( helpTagName, helpHTML )[0];
+ helpDOM.style.position = 'fixed';
+ helpDOM.style.top = '0';
+ helpDOM.style.width = '50vw';
+ helpDOM.style.height = '100vh';
+ helpDOM.style.background = 'rgba(255,255,255,0.5)';
+ helpDOM.style.zIndex = '99';
+ div.appendChild(helpDOM);
+
+ const backDiv = document.createElement('div');
+ backDiv.style.position = 'fixed';
+ backDiv.style.top = '0';
+ backDiv.style.width = '100vw';
+ backDiv.style.height = '100vh';
+ backDiv.style.zIndex = '98';
+ div.appendChild(backDiv);
+
+ document.body.appendChild(div);
+
+ helpDOM.addEventListener('click',e=>{
+ $qs('#RequestRewriteInfoForm')[0].value += e.target.textContent + "\n" + url + e.target.getAttribute('href') + '\n\n';
+ });
+
+ backDiv.addEventListener('click',e=>{
+ div.style.display = 'none';
+ });
+ }
})()
/*
* @title teratail 修正依頼を定型文で送る
* @description https://teratail.com/questions/233570 からインスパイア。
* @include https://teratail.com/*
* @license public domain
* @private
* @javascript_url
* @require
*/
void (async()=>{
const $id = document.getElementById.bind(document);
const $qs = ( s, c = document ) => {
const r = Array.from( c.querySelectorAll(s) );
return r.length ? r : [document.createDocumentFragment()];
};
const url = "https://teratail.com/help/question-tips";
const helpTagName = '.P-navigation';
const wrapperTagName = 'g5G38emWp5UZ';
if ( $id( wrapperTagName ) ){
$id( wrapperTagName ).style.display = 'block';
} else {
const helpHTML = ( new DOMParser() ).parseFromString(
await(await fetch(url)).text(),
'text/html'
);
const div = document.createElement('div');
div.id = wrapperTagName;
const helpDOM = $qs( helpTagName, helpHTML )[0];
helpDOM.style.position = 'fixed';
helpDOM.style.top = '0';
helpDOM.style.width = '50vw';
helpDOM.style.height = '100vh';
helpDOM.style.background = 'rgba(255,255,255,0.5)';
helpDOM.style.zIndex = '99';
div.appendChild(helpDOM);
const backDiv = document.createElement('div');
backDiv.style.position = 'fixed';
backDiv.style.top = '0';
backDiv.style.width = '100vw';
backDiv.style.height = '100vh';
backDiv.style.zIndex = '98';
div.appendChild(backDiv);
document.body.appendChild(div);
helpDOM.addEventListener('click',e=>{
$qs('#RequestRewriteInfoForm')[0].value += e.target.textContent + "\n" + url + e.target.getAttribute('href') + '\n\n';
});
backDiv.addEventListener('click',e=>{
div.style.display = 'none';
});
}
})()
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。