diff --git a/.gitignore b/.gitignore index 30e21f5..f952f91 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,7 @@ bld/ # Visual Studio 2015/2017 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot -/BantFlags/wwwroot/flags +/BantFlags/wwwroot/flags/* # Visual Studio 2017 auto generated files Generated\ Files/ diff --git a/BantFlags/Data/Database/GetPosts.cs b/BantFlags/Data/Database/GetPosts.cs index ac5ed10..9d05ea0 100644 --- a/BantFlags/Data/Database/GetPosts.cs +++ b/BantFlags/Data/Database/GetPosts.cs @@ -7,13 +7,13 @@ namespace BantFlags.Data.Database { public partial class DatabaseService { + // Maybe this could be better but I don't know SQL lol private readonly string GetPostsQuery = @"SELECT posts.post_nr, flags.flag FROM flags LEFT JOIN (postflags) ON (postflags.flag = flags.id) LEFT JOIN (posts) ON (postflags.post_nr = posts.id) WHERE FIND_IN_SET(posts.post_nr, (@posts))"; /// /// Returns the post numbers and their flags from the post numbers in the input. /// /// List of post numbers on the page. - /// public async Task>> GetPosts(string input) { using var rentedConnection = await ConnectionPool.RentConnectionAsync(); diff --git a/BantFlags/wwwroot/bantflags.meta.js b/BantFlags/bantflags.meta.js similarity index 100% rename from BantFlags/wwwroot/bantflags.meta.js rename to BantFlags/bantflags.meta.js diff --git a/BantFlags/wwwroot/bantflags.user.js b/BantFlags/bantflags.user.js similarity index 98% rename from BantFlags/wwwroot/bantflags.user.js rename to BantFlags/bantflags.user.js index 9f16209..34d62b3 100644 --- a/BantFlags/wwwroot/bantflags.user.js +++ b/BantFlags/bantflags.user.js @@ -10,7 +10,7 @@ // @exclude http*://archive.nyafuu.org/bant/statistics/ // @exclude http*://archived.moe/bant/statistics/ // @exclude http*://thebarchive.com/bant/statistics/ -// @version 0.8.0 +// @version 0.7.2 // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue @@ -48,6 +48,11 @@ var postNrs = []; // all post numbers in the thread. // DO NOT EDIT ANYTHING IN THIS SCRIPT DIRECTLY - YOUR FLAGS SHOULD BE CONFIGURED USING THE CONFIGURATION BOXES // +function ToggleFlagButton() { + let flagButton = document.getElementById("append_flag_button").disabled; + flagButton = flagButton === true ? false : true; +} + let elementsInClass = x => document.getElementsByClassName(x); let sliceCall = x => Array.prototype.slice.call(x); let firstChildInClass = (parent, className) => parent.getElementsByClassName(className)[0]; @@ -110,7 +115,7 @@ var nsetup = { // not anymore a clone of the original setup MakeRequest( "GET", back_end + api_flags, - "", // Because we're GETting. + "version=" + encodeURIComponent(version), function (resp) { debug('Loading flags'); if (resp.status !== 200) { diff --git a/Docs/api/get.org b/Docs/api/get.org new file mode 100644 index 0000000..87acc21 --- /dev/null +++ b/Docs/api/get.org @@ -0,0 +1,57 @@ +* /api/get + +** Database Query +Returns an =IEnumerable>= of post numbers and +their flags where the post numbers are contained in the input. + +** Compatibility +*** V1 +Minimum script version: 0 + +Flags are converted from an =IEnumerable>= to +a =List>= by joining the values in the +=DataRow= by "||", which are then split and converted into an array by +the script. + +We're doing a needless conversion at both ends which slows the whole +process down, but it's how extraflags is set up and we need to support +it. + +Data looks like this: +#+BEGIN_SRC javascript + [ + { + {"post_nr": "123"}, + {"regions": "flag1||flag2||flag3"} + }, + { + {"post_nr": "456"}, + {"regions": "flag4||flag3||flag3"} + } + ] +#+END_SRC + +*** V2 +Minimum script version: 2 + +Flags are converted from an =IEnumerable>= to +a =Dictionary>= which can then be parsed by +the script without any conversion. This format is the same as returned +from the database query, sans the extra information returned by a +=DataRow= + +Data looks like this: +#+BEGIN_SRC javascript + [ + 123: [ + "flag1", + "flag2", + "flag3" + ], + 456: [ + "flag4", + "flag3", + "flag3" + ] + ] +#+END_SRC