Skip to content

Commit

Permalink
add markdown settings to toggle on/off parsing for each content type
Browse files Browse the repository at this point in the history
  • Loading branch information
7dJx1qP committed Feb 10, 2024
1 parent 57c52cc commit a7fa469
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 52 deletions.
124 changes: 74 additions & 50 deletions plugins/stashMarkdown/stashMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,85 @@
el.innerHTML = marked.parse(el.innerHTML);
}

stash.addEventListener('page:tag:any', function () {
waitForElementByXpath("//span[contains(@class, 'detail-item-value') and contains(@class, 'description')]", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
let settings = null;
async function isMarkdownEnabled(page) {
if (settings === null) {
settings = await stash.getPluginConfig('stashMarkdown');
}
return settings?.[page];
}

stash.addEventListener('page:tag:any', async function () {
if (await isMarkdownEnabled('tags')) {
waitForElementByXpath("//span[contains(@class, 'detail-item-value') and contains(@class, 'description')]", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
}
});

stash.addEventListener('page:tags', function () {
waitForElementByXpath("//div[contains(@class, 'tag-description')]", function (xpath, el) {
for (const node of document.querySelectorAll('.tag-description')) {
node.style.whiteSpace = 'initial';
processMarkdown(node);
}
});
stash.addEventListener('page:tags', async function () {
if (await isMarkdownEnabled('tags')) {
waitForElementByXpath("//div[contains(@class, 'tag-description')]", function (xpath, el) {
for (const node of document.querySelectorAll('.tag-description')) {
node.style.whiteSpace = 'initial';
processMarkdown(node);
}
});
}
});

stash.addEventListener('page:scene', function () {
waitForElementByXpath("//div[@class='tab-content']//h6[contains(text(),'Details')]/following-sibling::p", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
stash.addEventListener('page:scene', async function () {
if (await isMarkdownEnabled('scenes')) {
waitForElementByXpath("//div[@class='tab-content']//h6[contains(text(),'Details')]/following-sibling::p", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
}
});

stash.addEventListener('page:gallery', function () {
waitForElementByXpath("//div[@class='tab-content']//h6[contains(text(),'Details')]/following-sibling::p", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
stash.addEventListener('page:gallery', async function () {
if (await isMarkdownEnabled('galleries')) {
waitForElementByXpath("//div[@class='tab-content']//h6[contains(text(),'Details')]/following-sibling::p", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
}
});

stash.addEventListener('page:movie:scenes', function () {
waitForElementByXpath("//span[contains(@class, 'detail-item-value') and contains(@class, 'synopsis')]", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
stash.addEventListener('page:movie:scenes', async function () {
if (await isMarkdownEnabled('movies')) {
waitForElementByXpath("//span[contains(@class, 'detail-item-value') and contains(@class, 'synopsis')]", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
}
});

stash.addEventListener('page:movies', function () {
waitForElementByXpath("//div[contains(@class, 'movie-card__description')]", function (xpath, el) {
for (const node of document.querySelectorAll('.movie-card__description')) {
node.style.whiteSpace = 'initial';
processMarkdown(node);
}
});
stash.addEventListener('page:movies', async function () {
if (await isMarkdownEnabled('movies')) {
waitForElementByXpath("//div[contains(@class, 'movie-card__description')]", function (xpath, el) {
for (const node of document.querySelectorAll('.movie-card__description')) {
node.style.whiteSpace = 'initial';
processMarkdown(node);
}
});
}
});

// Performer details is visible regardless of chosen tab
function performerPageHandler() {
waitForElementByXpath("//span[contains(@class, 'detail-item-value') and contains(@class, 'details')]", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
async function performerPageHandler() {
if (await isMarkdownEnabled('performers')) {
waitForElementByXpath("//span[contains(@class, 'detail-item-value') and contains(@class, 'details')]", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
}
}
stash.addEventListener('page:performer:scenes', performerPageHandler);
stash.addEventListener('page:performer:galleries', performerPageHandler);
Expand All @@ -81,12 +103,14 @@
stash.addEventListener('page:performer:details', performerPageHandler);

// Studio details is visible regardless of chosen tab
function studioPageHandler() {
waitForElementByXpath("//span[contains(@class, 'detail-item-value') and contains(@class, 'details')]", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
async function studioPageHandler() {
if (await isMarkdownEnabled('studios')) {
waitForElementByXpath("//span[contains(@class, 'detail-item-value') and contains(@class, 'details')]", function (xpath, el) {
el.style.display = 'block';
el.style.whiteSpace = 'initial';
processMarkdown(el);
});
}
}
stash.addEventListener('page:studio:galleries', studioPageHandler);
stash.addEventListener('page:studio:images', studioPageHandler);
Expand Down
23 changes: 21 additions & 2 deletions plugins/stashMarkdown/stashMarkdown.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
name: Stash Markdown
# requires: stashUserscriptLibrary7dJx1qP
description: Adds markdown parsing to tag description fields
version: 0.3.0
version: 0.4.0
ui:
requires:
- stashUserscriptLibrary7dJx1qP
javascript:
- https://cdnjs.cloudflare.com/ajax/libs/marked/4.2.2/marked.min.js
- stashMarkdown.js
- stashMarkdown.js
settings:
scenes:
displayName: Scenes
type: BOOLEAN
movies:
displayName: Movies
type: BOOLEAN
galleries:
displayName: Galleries
type: BOOLEAN
performers:
displayName: Performers
type: BOOLEAN
studios:
displayName: Studios
type: BOOLEAN
tags:
displayName: Tags
type: BOOLEAN

0 comments on commit a7fa469

Please sign in to comment.