Skip to content

Instantly share code, notes, and snippets.

@vzvu3k6k
Created February 19, 2016 12:24
Show Gist options
  • Save vzvu3k6k/4029aea8a7a919bd8f89 to your computer and use it in GitHub Desktop.
Save vzvu3k6k/4029aea8a7a919bd8f89 to your computer and use it in GitHub Desktop.
qiita-fix_table_completion.user.js
// ==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);
}
@vzvu3k6k
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment