Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user.js版を生成する #95

Merged
merged 6 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

グローバル変数への依存を減らしたいのでwebSiteNameは waitElementの引数にしてほしいです。

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