From 91a743900794f7437f9ef7807906953392faa8bc Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Thu, 16 Mar 2023 01:12:06 +1300 Subject: [PATCH] Fix yugioh wiki card pages (only half-fixed in offline environments) --- archiver/archiver.rkt | 2 +- archiver/info.rkt | 3 +++ archiver/req.rktd | 1 + lib/mime.types | 1 + lib/tree-updater.rkt | 21 +++++++++++++++++++++ src/application-globals.rkt | 2 +- 6 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 archiver/info.rkt create mode 100644 archiver/req.rktd diff --git a/archiver/archiver.rkt b/archiver/archiver.rkt index 5eb56c8..edd0d2b 100644 --- a/archiver/archiver.rkt +++ b/archiver/archiver.rkt @@ -100,7 +100,7 @@ (theme "default") (theme "light") (theme "dark") - (cons (format "https://~a.fandom.com/load.php?lang=en&modules=skin.fandomdesktop.styles%7Cext.fandom.PortableInfoboxFandomDesktop.css%7Cext.fandom.GlobalComponents.CommunityHeaderBackground.css%7Cext.gadget.site-styles%2Csound-styles%7Csite.styles&only=styles&skin=fandomdesktop" wikiname) + (cons (format "https://~a.fandom.com/load.php?lang=en&modules=site.styles%7Cskin.fandomdesktop.styles%7Cext.fandom.PortableInfoboxFandomDesktop.css%7Cext.fandom.GlobalComponents.CommunityHeaderBackground.css%7Cext.gadget.site-styles%2Csound-styles&only=styles&skin=fandomdesktop" wikiname) (build-path save-dir "site.css")))) (for ([style styles] [i (in-naturals)]) diff --git a/archiver/info.rkt b/archiver/info.rkt new file mode 100644 index 0000000..17bb747 --- /dev/null +++ b/archiver/info.rkt @@ -0,0 +1,3 @@ +#lang info + +(define build-deps '("rackunit-lib" "web-server-lib" "http-easy-lib" "html-parsing" "html-writing" "json-pointer" "ini-lib" "memo" "net-cookies-lib" "gui-easy-lib" "sql" "charterm" "cli")) diff --git a/archiver/req.rktd b/archiver/req.rktd new file mode 100644 index 0000000..e2d2fc2 --- /dev/null +++ b/archiver/req.rktd @@ -0,0 +1 @@ +((local ("."))) diff --git a/lib/mime.types b/lib/mime.types index d31a2ac..c06a1e9 100644 --- a/lib/mime.types +++ b/lib/mime.types @@ -17,6 +17,7 @@ image/png png image/tiff tiff image/vnd.wap.wbmp wbmp image/x-icon ico +image/vnd.microsoft.icon ico image/x-jng jng image/x-ms-bmp bmp image/svg+xml svg diff --git a/lib/tree-updater.rkt b/lib/tree-updater.rkt index 98a989b..074c5a1 100644 --- a/lib/tree-updater.rkt +++ b/lib/tree-updater.rkt @@ -97,6 +97,9 @@ (string-replace-curried "pi-collapse-closed" "") (string-replace-curried "pi-collapse" ""))) + (define (cardimage-class-updater c) + (string-append c " bw-updated-cardtable-cardimage")) + (define attributes-updater (compose1 ; uncollapsing @@ -184,6 +187,24 @@ ((class "table-scroller")) ((,element-type (@ (data-scrolling) ,@attributes) ,@children)))] + ; HACK for /yugioh/wiki/Pot_of_Greed: move card images above tables + [(and (eq? element-type 'table) + (has-class? "cardtable" attributes) + (not (has-class? "bw-updated-cardtable-cardimage" attributes))) + (define (is-cardimage? t a c) (and (eq? t 'td) + (has-class? "cardtable-cardimage" a))) + (define cardimage ((query-selector is-cardimage? element))) + (if (not cardimage) + (list element-type attributes children) + (let ([new-cardtable (update-tree + (λ (e t a c) + (if (is-cardimage? t a c) + return-no-element + (list t a c))) + `(,element-type + (@ ,(attribute-maybe-update 'class cardimage-class-updater attributes)) + ,@children))]) + (list 'div null (list cardimage new-cardtable))))] ; exclude empty figcaptions [(and (eq? element-type 'figcaption) (or (eq? (length (filter element-is-element? children)) 0) diff --git a/src/application-globals.rkt b/src/application-globals.rkt index 4a797ad..02038ab 100644 --- a/src/application-globals.rkt +++ b/src/application-globals.rkt @@ -166,7 +166,7 @@ (define styles (list (format "~a/wikia.php?controller=ThemeApi&method=themeVariables&variant=~a" origin (user-cookies^-theme user-cookies)) - (format "~a/load.php?lang=en&modules=skin.fandomdesktop.styles%7Cext.fandom.PortableInfoboxFandomDesktop.css%7Cext.fandom.GlobalComponents.CommunityHeaderBackground.css%7Cext.gadget.site-styles%2Csound-styles%7Csite.styles&only=styles&skin=fandomdesktop" origin))) + (format "~a/load.php?lang=en&modules=site.styles%7Cskin.fandomdesktop.styles%7Cext.fandom.PortableInfoboxFandomDesktop.css%7Cext.fandom.GlobalComponents.CommunityHeaderBackground.css%7Cext.gadget.site-styles%2Csound-styles&only=styles&skin=fandomdesktop" origin))) (if (config-true? 'strict_proxy) (map u-proxy-url styles) styles)]