Last active
February 1, 2024 21:19
-
-
Save GChristensen/c4be3bb8508ad13d982c2f57ac302eb8 to your computer and use it in GitHub Desktop.
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
let AUTH_TOKEN = "<token from Settings tab>"; | |
let APP_BASE = "http://<feedxcavator host>:10000"; | |
CmdUtils.CreateCommand({ | |
name: "filter-word", | |
uuid: "0927A434-42CD-4BEC-96DC-9EB0FA884EE7", | |
description: "Add a regular expression to Feedxcavator word filter.", | |
arguments: [{role: "object", nountype: noun_arb_text, label: "regex"}, | |
{role: "instrument", nountype: noun_arb_text, label: "word-filter"}, // with | |
], | |
previewDelay: 1000, | |
preview: function(pblock, args, {Bin}) {}, | |
execute: function(args, {Bin}) { | |
let word_filter = args.instrument && args.instrument.text | |
? args.instrument.text | |
: "default"; | |
let expr = args.object && args.object.text | |
? args.object.text | |
: null; | |
if (expr) | |
$.ajax({url: `${APP_BASE}/api/wordfilter/add-regex`, | |
type: "POST", | |
data: JSON.stringify({"regex": expr, "word-filter": word_filter}), | |
contentType: "application/json", | |
headers: {"x-feedxcavator-auth": AUTH_TOKEN} | |
}); | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "unfilter-word", | |
uuid: "0927A434-42CD-4BEC-96DC-9EB0FA884EE7", | |
description: "Remove a regular expression to Feedxcavator word filter.", | |
arguments: [{role: "object", nountype: noun_arb_text, label: "regex"}, | |
{role: "instrument", nountype: noun_arb_text, label: "word-filter"}, // with | |
], | |
previewDelay: 1000, | |
preview: function(pblock, args, {Bin}) {}, | |
execute: function(args, {Bin}) { | |
let word_filter = args.instrument && args.instrument.text | |
? args.instrument.text | |
: "default"; | |
let expr = args.object && args.object.text | |
? args.object.text | |
: null; | |
if (expr) | |
$.ajax({url: `${APP_BASE}/api/wordfilter/remove-regex`, | |
type: "POST", | |
data: JSON.stringify({"regex": expr, "word-filter": word_filter}), | |
contentType: "application/json", | |
headers: {"x-feedxcavator-auth": AUTH_TOKEN} | |
}); | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "word-filter", | |
uuid: "0927A434-42CD-4BEC-96DC-9EB0FA884EE7", | |
description: "List Feedxcavator word filter contents.", | |
arguments: [{role: "object", nountype: noun_arb_text, label: "word-filter"}, | |
], | |
previewDelay: 1000, | |
preview: function(pblock, args, {Bin}) { | |
let word_filter = args.object && args.object.text | |
? args.object.text | |
: "default"; | |
CmdUtils.previewAjax(pblock, | |
{url: `${APP_BASE}/api/wordfilter/list-words`, | |
type: "POST", | |
data: JSON.stringify({"word-filter": word_filter}), | |
contentType: "application/json", | |
dataType: "json", | |
headers: {"x-feedxcavator-auth": AUTH_TOKEN}, | |
success: (words) => { | |
pblock.innerHTML = `<ul>${words.sort().map(w => "<li>" + w + "</li>").join("")}</ul>`; | |
}}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment