Skip to content

Commit

Permalink
Merge pull request #95 from pastak/userjs
Browse files Browse the repository at this point in the history
user.js版を生成する
  • Loading branch information
inajob authored Sep 11, 2021
2 parents 563e806 + 442e451 commit e5ccc46
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ cat ./src/toICN-before.js > toICN-debug.js
cat ./src/toICN-core.js >> toICN-debug.js
cat ./src/toICN-after.js >> toICN-debug.js

cat ./template/user.js.header > toICN.user.js
cat ./toICN-debug.js >> toICN.user.js

./template/README.sh > README.md
58 changes: 42 additions & 16 deletions src/toICN-after.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,49 @@ let detectedKey;
let keyChords;
let isAutoDetected = false;

//ChordやKeyを読む
let rawKeyChords = exports.readKeyChords(webSiteName);
keyChords = rawKeyChords.keyChords;
detectedKey = rawKeyChords.key;
function main () {
//ChordやKeyを読む
let rawKeyChords = exports.readKeyChords(webSiteName);
keyChords = rawKeyChords.keyChords;
detectedKey = rawKeyChords.key;

// キーが書かれていないときは、キーを自動判定する
if(detectedKey.keyNo == -1){
detectedKey = exports.autoDetectKey(keyChords);
// キーが書かれていないときは、キーを自動判定する
if(detectedKey.keyNo == -1){
detectedKey = exports.autoDetectKey(keyChords);

isAutoDetected = true;
}
isAutoDetected = true;
}

// キーの手動設定
var result = prompt("Key:" + detectedKey.key + (isAutoDetected?"(コード譜を元に自動判定されたキー)":"(Webサイトが指定したキー)") +"\n別のキーを指定したい場合は、下にキーを入力してください。(例:C)\nよくわからなければ、そのままOKを押してください。\nキャンセルを押すと変換しません。");
// キャンセルされると置き換えを実行しない
if (result === null) return;
let resultMatch = result.match(/([A-G](#|b){0,1}m{0,1})$/);
let specifiedKey = new exports.Key(resultMatch?resultMatch[1]:"");
if(specifiedKey.keyNo != -1){isAutoKeyDetection = false;}

//表示書き換え関係
exports.updateChords(keyChords, isAutoKeyDetection?detectedKey:specifiedKey, isAutoKeyDetection);
};

// キーの手動設定
var result = prompt("Key:" + detectedKey.key + (isAutoDetected?"(コード譜を元に自動判定されたキー)":"(Webサイトが指定したキー)") +"\n別のキーを指定したい場合は、下にキーを入力してください。(例:C)\nよくわからなければ、そのままOKを押してください。");
let resultMatch = result.match(/([A-G](#|b){0,1}m{0,1})$/);
let specifiedKey = new exports.Key(resultMatch?resultMatch[1]:"");
if(specifiedKey.keyNo != -1){isAutoKeyDetection = false;}
function waitElement(webSiteName, cb) {
let selector;
if (webSiteName === "ufret") {
selector = '#my-chord-data .chord ruby rt';
}
if (!selector) return cb();

//表示書き換え関係
exports.updateChords(keyChords, isAutoKeyDetection?detectedKey:specifiedKey, isAutoKeyDetection);
const timer = setInterval(function () {
const resolve = function () {
clearInterval(timer);
cb();
};
if (!!document.querySelector(selector)) resolve();
}, 300);
}

if (document.readyState === 'complete' || document.readyState === 'interactive') {
waitElement(webSiteName, main);
} else {
document.addEventListener('DOMContentLoaded', function () {waitElement(webSiteName, main)});
}
11 changes: 11 additions & 0 deletions template/user.js.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// ==UserScript==
// @name toInstaChord ICN
// @namespace https://github.com/inajob/toICN
// @version 0.1
// @homepage https://github.com/inajob/toICN
// @match https://ja.chordwiki.org/wiki/*
// @match https://www.ufret.jp/song.php?data=*
// @match https://gakufu.gakki.me/m/*
// @match https://music.j-total.net/data/*
// @grant none
// ==/UserScript==
58 changes: 42 additions & 16 deletions toICN-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,49 @@ let detectedKey;
let keyChords;
let isAutoDetected = false;

//ChordやKeyを読む
let rawKeyChords = exports.readKeyChords(webSiteName);
keyChords = rawKeyChords.keyChords;
detectedKey = rawKeyChords.key;
function main () {
//ChordやKeyを読む
let rawKeyChords = exports.readKeyChords(webSiteName);
keyChords = rawKeyChords.keyChords;
detectedKey = rawKeyChords.key;

// キーが書かれていないときは、キーを自動判定する
if(detectedKey.keyNo == -1){
detectedKey = exports.autoDetectKey(keyChords);
// キーが書かれていないときは、キーを自動判定する
if(detectedKey.keyNo == -1){
detectedKey = exports.autoDetectKey(keyChords);

isAutoDetected = true;
}
isAutoDetected = true;
}

// キーの手動設定
var result = prompt("Key:" + detectedKey.key + (isAutoDetected?"(コード譜を元に自動判定されたキー)":"(Webサイトが指定したキー)") +"\n別のキーを指定したい場合は、下にキーを入力してください。(例:C)\nよくわからなければ、そのままOKを押してください。");
let resultMatch = result.match(/([A-G](#|b){0,1}m{0,1})$/);
let specifiedKey = new exports.Key(resultMatch?resultMatch[1]:"");
if(specifiedKey.keyNo != -1){isAutoKeyDetection = false;}
// キーの手動設定
var result = prompt("Key:" + detectedKey.key + (isAutoDetected?"(コード譜を元に自動判定されたキー)":"(Webサイトが指定したキー)") +"\n別のキーを指定したい場合は、下にキーを入力してください。(例:C)\nよくわからなければ、そのままOKを押してください。\nキャンセルを押すと変換しません。");
// キャンセルされると置き換えを実行しない
if (result === null) return;
let resultMatch = result.match(/([A-G](#|b){0,1}m{0,1})$/);
let specifiedKey = new exports.Key(resultMatch?resultMatch[1]:"");
if(specifiedKey.keyNo != -1){isAutoKeyDetection = false;}

//表示書き換え関係
exports.updateChords(keyChords, isAutoKeyDetection?detectedKey:specifiedKey, isAutoKeyDetection);
//表示書き換え関係
exports.updateChords(keyChords, isAutoKeyDetection?detectedKey:specifiedKey, isAutoKeyDetection);
};

function waitElement(webSiteName, cb) {
let selector;
if (webSiteName === "ufret") {
selector = '#my-chord-data .chord ruby rt';
}
if (!selector) return cb();

const timer = setInterval(function () {
const resolve = function () {
clearInterval(timer);
cb();
};
if (!!document.querySelector(selector)) resolve();
}, 300);
}

if (document.readyState === 'complete' || document.readyState === 'interactive') {
waitElement(webSiteName, main);
} else {
document.addEventListener('DOMContentLoaded', function () {waitElement(webSiteName, main)});
}
2 changes: 1 addition & 1 deletion toICN.bookmarklet

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion toICN.js

Large diffs are not rendered by default.

Loading

0 comments on commit e5ccc46

Please sign in to comment.