Move userscript to root of project. add documentation

dotnetflags
C-xC-c 5 years ago
parent d9d5a47b12
commit bd6a17e353

2
.gitignore vendored

@ -32,7 +32,7 @@ bld/
# Visual Studio 2015/2017 cache/options directory # Visual Studio 2015/2017 cache/options directory
.vs/ .vs/
# Uncomment if you have tasks that create the project's static files in wwwroot # 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 # Visual Studio 2017 auto generated files
Generated\ Files/ Generated\ Files/

@ -7,13 +7,13 @@ namespace BantFlags.Data.Database
{ {
public partial class DatabaseService 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))"; 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))";
/// <summary> /// <summary>
/// Returns the post numbers and their flags from the post numbers in the input. /// Returns the post numbers and their flags from the post numbers in the input.
/// </summary> /// </summary>
/// <param name="input">List of post numbers on the page.</param> /// <param name="input">List of post numbers on the page.</param>
/// <returns></returns>
public async Task<IEnumerable<IGrouping<int, DataRow>>> GetPosts(string input) public async Task<IEnumerable<IGrouping<int, DataRow>>> GetPosts(string input)
{ {
using var rentedConnection = await ConnectionPool.RentConnectionAsync(); using var rentedConnection = await ConnectionPool.RentConnectionAsync();

@ -10,7 +10,7 @@
// @exclude http*://archive.nyafuu.org/bant/statistics/ // @exclude http*://archive.nyafuu.org/bant/statistics/
// @exclude http*://archived.moe/bant/statistics/ // @exclude http*://archived.moe/bant/statistics/
// @exclude http*://thebarchive.com/bant/statistics/ // @exclude http*://thebarchive.com/bant/statistics/
// @version 0.8.0 // @version 0.7.2
// @grant GM_xmlhttpRequest // @grant GM_xmlhttpRequest
// @grant GM_getValue // @grant GM_getValue
// @grant GM_setValue // @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 // 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 elementsInClass = x => document.getElementsByClassName(x);
let sliceCall = x => Array.prototype.slice.call(x); let sliceCall = x => Array.prototype.slice.call(x);
let firstChildInClass = (parent, className) => parent.getElementsByClassName(className)[0]; let firstChildInClass = (parent, className) => parent.getElementsByClassName(className)[0];
@ -110,7 +115,7 @@ var nsetup = { // not anymore a clone of the original setup
MakeRequest( MakeRequest(
"GET", "GET",
back_end + api_flags, back_end + api_flags,
"", // Because we're GETting. "version=" + encodeURIComponent(version),
function (resp) { function (resp) {
debug('Loading flags'); debug('Loading flags');
if (resp.status !== 200) { if (resp.status !== 200) {

@ -0,0 +1,57 @@
* /api/get
** Database Query
Returns an =IEnumerable<IGrouping<int, DataRow>>= 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<IGrouping<int, DataRow>>= to
a =List<Dictionary<string, string>>= 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<IGrouping<int, DataRow>>= to
a =Dictionary<int, IEnumerable<string>>= 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
Loading…
Cancel
Save