20,741
edits
m (→On quoting) |
m (→The Script: add simple framework for showing a jQuery based setup/configuration dialog using GM_setValue/getValue based script persistence) |
||
| Line 271: | Line 271: | ||
// ==UserScript== | // ==UserScript== | ||
// @name Instant-Cquotes | // @name Instant-Cquotes | ||
// @version 0. | // @version 0.30 | ||
// @description Automatically converts FlightGear mailing list and forum quotes into MediaWiki markup (cquotes). | // @description Automatically converts FlightGear mailing list and forum quotes into MediaWiki markup (cquotes). | ||
// @description:it Converte automaticamente citazioni dalla mailing list e dal forum di FlightGear in marcatori MediaWiki (cquote). | // @description:it Converte automaticamente citazioni dalla mailing list e dal forum di FlightGear in marcatori MediaWiki (cquote). | ||
| Line 284: | Line 284: | ||
// @require https://code.jquery.com/ui/1.11.4/jquery-ui.min.js | // @require https://code.jquery.com/ui/1.11.4/jquery-ui.min.js | ||
// @resource jQUI_CSS https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css | // @resource jQUI_CSS https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css | ||
// @grant GM_setValue | |||
// @grant GM_getValue | |||
// @grant GM_addStyle | // @grant GM_addStyle | ||
// @grant GM_getResourceText | // @grant GM_getResourceText | ||
| Line 315: | Line 317: | ||
var USE_NG=false; | var USE_NG=false; | ||
function set_persistent(key,value) { | |||
// https://wiki.greasespot.net/GM_setValue | |||
GM_setValue(key,value); | |||
} //make_persistent | |||
function get_persistent(key, default_value) { | |||
https://wiki.greasespot.net/GM_getValue | |||
return GM_getValue(key,default_value); | |||
} // get_persistent | |||
// hash with supported websites/URLs | // hash with supported websites/URLs | ||
| Line 427: | Line 438: | ||
width: 'auto', | width: 'auto', | ||
buttons: [ | buttons: [ | ||
{ | |||
text: 'Setup', | |||
click: setupDialog | |||
}, | |||
{ | { | ||
text: 'Select all', | text: 'Select all', | ||
| Line 569: | Line 584: | ||
} | } | ||
if (selection.toString() === '') { | if (selection.toString() === '') { | ||
dbLog(' | dbLog('No text is selected, aborting function'); | ||
return; | return; | ||
} | } | ||
if (!checkValid(selection, profile)) { | if (!checkValid(selection, profile)) { | ||
dbLog(' | dbLog('Selection is not valid, aborting function'); | ||
return; | return; | ||
} | } | ||
| Line 581: | Line 596: | ||
var transform = profile[field].transform; | var transform = profile[field].transform; | ||
if (transform !== undefined) { | if (transform !== undefined) { | ||
dbLog(' | dbLog('Field \'' + field + '\' before transformation:\n\'' + fieldData + '\''); | ||
fieldData = applyTransformations(fieldData, transform); | fieldData = applyTransformations(fieldData, transform); | ||
dbLog(' | dbLog('Field \'' + field + '\' after transformation:\n\'' + fieldData + '\''); | ||
} | } | ||
output[field] = fieldData; | output[field] = fieldData; | ||
| Line 592: | Line 607: | ||
} | } | ||
// Gets to correct profile | // Gets to correct profile | ||
function setupDialog() { | |||
alert("configuration dialog is not yet implemented"); | |||
} // setupDialog | |||
function getProfile() { | function getProfile() { | ||
for (var profile in CONFIG) { | for (var profile in CONFIG) { | ||
if (window.location.href.match(CONFIG[profile].url_reg) !== null) { | if (window.location.href.match(CONFIG[profile].url_reg) !== null) { | ||
dbLog("Matching profile found"); | |||
var invocations=get_persistent(GM_info.script.version,0); | |||
dbLog("Number of script invocations for version "+GM_info.script.version+" is:"+invocations); | |||
if (invocations==0) { | |||
var response = confirm("This is your first time running version "+GM_info.script.version+ "\nConfigure now?"); | |||
if (response){ | |||
// show configuration dialog (jQuery) | |||
setupDialog(); | |||
} | |||
else{ | |||
} // don't configure | |||
} | |||
// increment number of invocations, use the version number as the key, to prevent the config dialog from showing up again | |||
set_persistent(GM_info.script.version, invocations+1) | |||
return CONFIG[profile]; | return CONFIG[profile]; | ||
} | } | ||