Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[x/gallery-metadata] Create metadata JSON file with gallery name #19

Open
ZorroGuevara opened this issue Jul 16, 2021 · 4 comments
Open

Comments

@ZorroGuevara
Copy link

Currently the button 'Metadata JSON' create a file named "json". It'll be great of the json file would be named by the gallery title.

@nikgtasa
Copy link

Yeah. I tried messing around with the script but failed. Hopefully author can do it.

@morning-paradigm
Copy link

Here's a dirty fix made with ChatGPT and some tinkering.
Replace function setupGalleryPage (line 863) and function createGalleryPageDownloadLink (line 873) with the following

code:
function setupGalleryPage() {
	createGalleryPageDownloadLinkEN();
	createGalleryPageDownloadLinkJP();

	windowMessage.registerCommand("galleryInfoRequest", (e) => {
		const data = getFromHtml(document, window.location.href);
		if (data === null) { return; }
		windowMessage.post(e.source, "galleryInfoResponse", toCommonJson(data));
	});
}

function createGalleryPageDownloadLinkEN() {
    const galleryRightSidebar = require("../api/gallery-right-sidebar");
    const link = galleryRightSidebar.createLink("Metadata JSON EN", 0).link;
    if (link === null) { return; }

    // Get the text contents of the h1 element with id "gn"
    const fileName = document.querySelector('h1#gn').textContent;

    link.setAttribute("download", `${fileName}.json`);
    link.href = "#";

    link.addEventListener("click", onDownloadLinkClicked, false);
    link.addEventListener("auxclick", onDownloadLinkClicked, false);
}

function createGalleryPageDownloadLinkJP() {
    const galleryRightSidebar = require("../api/gallery-right-sidebar");
    const link = galleryRightSidebar.createLink("Metadata JSON JP", 0).link;
    if (link === null) { return; }

    // Get the text contents of the h1 element with id "gj"
    const fileName = document.querySelector('h1#gj').textContent;

    link.setAttribute("download", `${fileName}.json`);
    link.href = "#";

    link.addEventListener("click", onDownloadLinkClicked, false);
    link.addEventListener("auxclick", onDownloadLinkClicked, false);
}

Or replace just function createGalleryPageDownloadLink (line 873) with:

For English title only:
function createGalleryPageDownloadLink() {
    const galleryRightSidebar = require("../api/gallery-right-sidebar");
    const link = galleryRightSidebar.createLink("Metadata JSON", 0).link;
    if (link === null) { return; }

    // Get the text contents of the h1 element with id "gn"
    const fileName = document.querySelector('h1#gn').textContent;

    link.setAttribute("download", `${fileName}.json`);
    link.href = "#";

    link.addEventListener("click", onDownloadLinkClicked, false);
    link.addEventListener("auxclick", onDownloadLinkClicked, false);
}
For Japanese title only:
function createGalleryPageDownloadLink() {
    const galleryRightSidebar = require("../api/gallery-right-sidebar");
    const link = galleryRightSidebar.createLink("Metadata JSON", 0).link;
    if (link === null) { return; }

    // Get the text contents of the h1 element with id "gj"
    const fileName = document.querySelector('h1#gj').textContent;

    link.setAttribute("download", `${fileName}.json`);
    link.href = "#";

    link.addEventListener("click", onDownloadLinkClicked, false);
    link.addEventListener("auxclick", onDownloadLinkClicked, false);
}

I couldn't figure out how to put the links into <p>s instead of <div>s to make it look compact without breaking stuff. Feel free to suggest.

@ZorroGuevara
Copy link
Author

Here's a dirty fix made with ChatGPT and some tinkering. Replace function setupGalleryPage (line 863) and function createGalleryPageDownloadLink (line 873) with the following
code:

Or replace just function createGalleryPageDownloadLink (line 873) with:
For English title only:
For Japanese title only:

I couldn't figure out how to put the links into <p>s instead of <div>s to make it look compact without breaking stuff. Feel free to suggest.

It's working! Thanks!

@nikgtasa
Copy link

Do you think it's possible to make the script work on the entire page worth of galleries?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@nikgtasa @morning-paradigm @ZorroGuevara and others