Created
February 19, 2016 12:24
-
-
Save vzvu3k6k/4029aea8a7a919bd8f89 to your computer and use it in GitHub Desktop.
qiita-fix_table_completion.user.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Qiita: Fix Table Completion | |
// @description Disable table completion ({numbers}x{numbers}) when either numbers starts with zero | |
// @version 1.0 | |
// @match http://qiita.com/* | |
// @grant none | |
// @noframes | |
// @namespace http://vzvu3k6k.tk/ | |
// @license CC0 | |
// ==/UserScript== | |
// http://qiita.com/7of9/items/f84dd4c0d943166a8cb6 | |
'use strict'; | |
let fix = () => { | |
$('textarea').each(function() { | |
let textComplete = $(this).data('textComplete'); | |
if (!textComplete) return; | |
textComplete.strategies.some((strategy) => { | |
if (strategy.match.source == '(^|\\s)((\\d+)x(\\d+))$') { | |
let original = strategy.search; | |
strategy.search = function(term, callback) { | |
if (term.split('x').some(n => n[0] === '0')) { | |
return callback([]); | |
} | |
return original.apply(this, arguments); | |
}; | |
return true; | |
} | |
}); | |
}); | |
}; | |
// Execute after initializing of jQuery.textcomplete | |
// I'm not sure this always works well. | |
if (document.readyState === 'complete') { | |
fix(); | |
} else { | |
window.addEventListener('load', fix); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
load
イベントが発生したときに実行するようにした。これでページ内のscriptタグの実行が終わったことが保証できるのかはわからない。@run-at
で指定できるが、特定の環境だけがサポートしている値(window-load
が使えるのはScriptishのみ)や、環境によって解釈が異なる値(Greasemonkeyのdocument-idle
)があるらしい。以下のサイトを参照した。最新の実装を反映しているのかは確認していない。