Re: Change the input tag field
Posted: Fri Jan 04, 2013 12:28 am
I'd suggest using a comma as a separator, if bubbles fail.
e-shuushuu discussion forums
https://e-shuushuu.net/forums/
Code: Select all
// ==UserScript==
// @name Selectize for E-shuushuu
// @namespace https://twitter.com/Meruni
// @version 0.1.0
// @description enter something useful
// @match http://e-shuushuu.net/upload/
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
// @require http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js
// @require http://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.9.0/js/standalone/selectize.min.js
// @resource selectizeCSS http://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.9.0/css/selectize.default.css
// @copyright 2014 Merun
// @grant GM_addStyle
// @grant GM_getResourceText
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_xmlhttpRequest
// ==/UserScript==
var css = GM_getResourceText('selectizeCSS');
GM_addStyle(css);
function replace(name, id) {
var tagList = JSON.parse(GM_getValue(name + "Tags")||"[]");
var searches = JSON.parse(GM_getValue(name + "Searches")||"{}") ;
function store(key, value) {
GM_setValue(key, JSON.stringify(value));
}
function localFind(input) {
return _.filter(tagList, function(value) {
return value.indexOf(input) === 1;
});
}
function formatTag(value) {
return {
value: value,
label: value.replace(/"/g, '')
};
}
var standardAttr = {
size: 40,
autocomplete: 'off',
type: 'text'
};
var tags = $("<input>").attr(standardAttr).addClass('text').attr('name', name);
$('#' + name).replaceWith(tags);
tags.selectize({
valueField: 'value',
labelField: 'label',
searchField: 'label',
dropdownParent: 'body',
options: [],
create: false,
load: function(query, callback) {
if (!query.length) return callback();
var local = localFind(query);
if(local.length){
callback(local.map(formatTag));
}
if(searches[query]!==undefined){
return;
}
$.get("/httpreq.php", {
mode: "tag_search",
tags: query,
type: id
},
function(res) {
searches[query] = '';
store(name+"Searches", searches);
var result = res.split('\n');
tagList = _.union(result, tagList);
store(name+"Tags", tagList);
var formated = result.map(formatTag);
callback(formated);
}
);
}
});
}
replace('tags', 1);
replace('source', 2);
replace('artist', 3);
replace('char', 4);