-
-
Save rRoler/a41d9cfc95c8444b06bcbe20066db10d to your computer and use it in GitHub Desktop.
Bookmark the mangadex-display_in_library.min.js code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as mangadex from './shared'; | |
import * as BM from '../shared'; | |
mangadex.newBookmarklet(async () => { | |
const authToken = mangadex.getAuthToken(); | |
const mangaStatuses: { | |
statuses: Record<string, string>; | |
} = await new Promise((resolve, reject) => | |
fetch('https://api.mangadex.org/manga/status', { | |
headers: { | |
Authorization: `${authToken.token_type} ${authToken.access_token}`, | |
}, | |
}) | |
.then((rsp) => resolve(rsp.json())) | |
.catch((e) => { | |
alert('Failed to fetch manga statuses!'); | |
reject(e); | |
}), | |
); | |
for (const mangaId in mangaStatuses.statuses) { | |
const mangaStatus = mangaStatuses.statuses[mangaId]; | |
document | |
.querySelectorAll('img[src^="https://mangadex.org/covers/"]') | |
.forEach((img) => { | |
const parentElement = img.parentElement?.parentElement; | |
if (!parentElement) return; | |
if (mangaId === img.getAttribute('src')?.split('/')[4]) { | |
const statusElement = document.createElement('span'); | |
BM.setStyle(statusElement, { | |
position: 'absolute', | |
top: '0', | |
right: '2%', | |
padding: '0px 0.2rem 0.1rem', | |
'border-bottom-right-radius': '0.25rem', | |
'border-bottom-left-radius': '0.25rem', | |
'font-weight': 'bold', | |
color: 'rbg(var(--color))', | |
'background-color': 'rgb(var(--md-primary))', | |
}); | |
statusElement.textContent = mangaStatus | |
.split('_') | |
.map( | |
(statusPart) => statusPart[0].toUpperCase() + statusPart.slice(1), | |
) | |
.join(' '); | |
parentElement.appendChild(statusElement); | |
} | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => {function newBookmarklet$1(websiteRegex, code) { | |
if (!new RegExp(websiteRegex).test(window.location.hostname)) return alert('Bookmarklet executed on the wrong website!'); | |
code(); | |
} | |
function getMatch(string, regex, index = 0) { | |
const regexMatches = string.match(regex); | |
if (regexMatches && regexMatches[index]) return regexMatches[index]; | |
} | |
function parseStorage(key) { | |
const value = localStorage.getItem(key); | |
if (value) return JSON.parse(value); | |
} | |
function setStyle(element, styles) { | |
for (const style in styles) element.style.setProperty(style, styles[style]); | |
} | |
const titleId = getMatch(window.location.pathname, /\/title\/+([-0-9a-f]{20,})/, 1) || getMatch(window.location.pathname, /\/title\/edit\/+([-0-9a-f]{20,})/, 1); | |
const newBookmarklet = (code, settings = {}) => { | |
newBookmarklet$1('^mangadex.org|canary.mangadex.dev', () => { | |
const isCreatePage = settings.createPage && /\/create\//.test(window.location.pathname); | |
const noticePart = 'You can execute this bookmarklet only on '; | |
if (settings.titlePage && !titleId && !isCreatePage) return alert(noticePart + 'a title page!'); | |
if (settings.editPage && !/\/edit\//.test(window.location.pathname) && !isCreatePage) return alert(noticePart + 'an edit page!'); | |
code(); | |
}); | |
}; | |
const getAuthToken = () => parseStorage('oidc.user:https://auth.mangadex.org/realms/mangadex:mangadex-frontend-stable') || parseStorage('oidc.user:https://auth.mangadex.org/realms/mangadex:mangadex-frontend-canary'); | |
newBookmarklet(async () => { | |
const authToken = getAuthToken(); | |
const mangaStatuses = await new Promise((resolve, reject) => fetch('https://api.mangadex.org/manga/status', { | |
headers: { | |
Authorization: `${authToken.token_type} ${authToken.access_token}` | |
} | |
}).then(rsp => resolve(rsp.json())).catch(e => { | |
alert('Failed to fetch manga statuses!'); | |
reject(e); | |
})); | |
for (const mangaId in mangaStatuses.statuses) { | |
const mangaStatus = mangaStatuses.statuses[mangaId]; | |
document.querySelectorAll('img[src^="https://mangadex.org/covers/"]').forEach(img => { | |
var _img$parentElement, _img$getAttribute; | |
const parentElement = (_img$parentElement = img.parentElement) === null || _img$parentElement === void 0 ? void 0 : _img$parentElement.parentElement; | |
if (!parentElement) return; | |
if (mangaId === ((_img$getAttribute = img.getAttribute('src')) === null || _img$getAttribute === void 0 ? void 0 : _img$getAttribute.split('/')[4])) { | |
const statusElement = document.createElement('span'); | |
setStyle(statusElement, { | |
position: 'absolute', | |
top: '0', | |
right: '2%', | |
padding: '0px 0.2rem 0.1rem', | |
'border-bottom-right-radius': '0.25rem', | |
'border-bottom-left-radius': '0.25rem', | |
'font-weight': 'bold', | |
color: 'var(--color)', | |
'background-color': 'var(--md-primary)' | |
}); | |
statusElement.textContent = mangaStatus.split('_').map(statusPart => statusPart[0].toUpperCase() + statusPart.slice(1)).join(' '); | |
parentElement.appendChild(statusElement); | |
} | |
}); | |
} | |
});})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(() => {function t(t,e,a=0){const o=t.match(e);if(o&&o[a])return o[a]}function e(t){const e=localStorage.getItem(t);if(e)return JSON.parse(e)}function a(t,e){for(const a in e)t.style.setProperty(a,e[a])}const o=t(window.location.pathname,/\/title\/+([-0-9a-f]{20,})/,1)||t(window.location.pathname,/\/title\/edit\/+([-0-9a-f]{20,})/,1);((t,e={})=>{(function(t,e){if(!new RegExp(t).test(window.location.hostname))return alert("Bookmarklet executed on the wrong website!");e()})("^mangadex.org|canary.mangadex.dev",(()=>{const a=e.createPage&&/\/create\//.test(window.location.pathname),n="You can execute this bookmarklet only on ";return!e.titlePage||o||a?!e.editPage||/\/edit\//.test(window.location.pathname)||a?void t():alert(n+"an edit page!"):alert(n+"a title page!")}))})((async()=>{const t=e("oidc.user:https://auth.mangadex.org/realms/mangadex:mangadex-frontend-stable")||e("oidc.user:https://auth.mangadex.org/realms/mangadex:mangadex-frontend-canary"),o=await new Promise(((e,a)=>fetch("https://api.mangadex.org/manga/status",{headers:{Authorization:`${t.token_type} ${t.access_token}`}}).then((t=>e(t.json()))).catch((t=>{alert("Failed to fetch manga statuses!"),a(t)}))));for(const t in o.statuses){const e=o.statuses[t];document.querySelectorAll('img[src^="https://mangadex.org/covers/"]').forEach((o=>{var n,r;const i=null===(n=o.parentElement)||void 0===n?void 0:n.parentElement;if(i&&t===(null===(r=o.getAttribute("src"))||void 0===r?void 0:r.split("/")[4])){const t=document.createElement("span");a(t,{position:"absolute",top:"0",right:"2%",padding:"0px 0.2rem 0.1rem","border-bottom-right-radius":"0.25rem","border-bottom-left-radius":"0.25rem","font-weight":"bold",color:"rbg(var(--color))","background-color":"rgb(var(--md-primary))"}),t.textContent=e.split("_").map((t=>t[0].toUpperCase()+t.slice(1))).join(" "),i.appendChild(t)}}))}}));})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment