Skip to content

Commit

Permalink
add: livechart-support
Browse files Browse the repository at this point in the history
  • Loading branch information
Metacor committed Jul 13, 2023
1 parent a6d5a2c commit 7ad2774
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 22 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "nyaa-linker",
"version": "1.1.1",
"version": "1.2.0",
"description": "Adds a button to Anime and Manga database websites that opens a relevant Nyaa search",
"scripts": {
"zip": "npm run firefox && npm run chrome",
"firefox": "mv src/manifest-firefox.json src/manifest.json && cd src && zip -r nyaa-linker-%npm_package_version%-%npm_lifecycle_event%.zip . -x manifest-*.json && cd .. && mv src/manifest.json src/manifest-firefox.json",
"chrome": "mv src/manifest-chrome.json src/manifest.json && cd src && zip -r nyaa-linker-%npm_package_version%-%npm_lifecycle_event%.zip . -x manifest-*.json && cd .. && mv src/manifest.json src/manifest-chrome.json"
"firefox": "mv src/manifest-firefox.json src/manifest.json && cd src && zip -r ..\\nyaa-linker-%npm_package_version%-%npm_lifecycle_event%.zip . -x manifest-*.json && cd .. && mv src/manifest.json src/manifest-firefox.json",
"chrome": "mv src/manifest-chrome.json src/manifest.json && cd src && zip -r ..\\nyaa-linker-%npm_package_version%-%npm_lifecycle_event%.zip . -x manifest-*.json && cd .. && mv src/manifest.json src/manifest-chrome.json"
},
"devDependencies": {
"eslint": "^8.26.0",
Expand Down
77 changes: 68 additions & 9 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ const searchNyaa = () => {
document.querySelector('.nyaaBtn') && document.querySelector('.nyaaBtn').remove();
createBtn(btnSpace);
btn.style.cssText = `
display: flex;
align-items: center;
justify-content: center;
height: 35px;
border-radius: 3px;
background: rgb(var(--color-blue));
color: #fff;
margin-bottom: 20px;`;
display: flex;
align-items: center;
justify-content: center;
height: 35px;
border-radius: 3px;
background: rgb(var(--color-blue));
color: #fff;
margin-bottom: 20px;`;
});
break;

Expand All @@ -163,6 +163,56 @@ const searchNyaa = () => {
btn.style.background = '#f5725f';
});
break;

case domain.includes('livechart.me'):
setTimeout(() => {
if (domain.includes(`livechart.me/${media}/`)) {
tempEng = document.querySelector('h4 small');
titleEng = tempEng.innerText;
tempEng.textContent = '';
titleJap = document.querySelector('h4').innerText;
tempEng.textContent = titleEng;

btnContainer = document.querySelector('#content > div.row div.text-center');
btnSpace = btnContainer.parentNode.insertBefore(document.createElement('div'), btnContainer);
createBtn(btnSpace);
btn.classList.add('button', 'expanded');
} else if (domain.includes("livechart.me/franchises/")) {
console.log("FUCK");
for (const card of document.querySelectorAll('.lc-anime')) {
titleJap = card.querySelector('.lc-anime-card--title').innerText;
btnContainer = card.querySelector('.lc-anime-card--related-links');
btnSpace = btnContainer.appendChild(document.createElement('li'));

createBtn(btnSpace);
btn.style.backgroundImage = 'url(https://i.imgur.com/9Fr2BRG.png)';
btn.style.backgroundSize = '20px';
btn.style.backgroundRepeat = 'no-repeat';
btn.style.backgroundPosition = 'center';
btn.classList.add('website-icon');

btn.href = `https://nyaa.si/?f=${filter}&c=${category}&q=${titleJap}&s=${sort}&o=${order}`;
btn.target = '_blank';
}
} else {
for (const card of document.querySelectorAll('.anime-card')) {
titleJap = card.querySelector('.main-title').innerText;
btnContainer = card.querySelector('.related-links');
btnSpace = btnContainer.appendChild(document.createElement('li'));

createBtn(btnSpace);
btn.style.backgroundImage = 'url(https://i.imgur.com/9Fr2BRG.png)';
btn.style.backgroundSize = '20px';
btn.style.backgroundRepeat = 'no-repeat';
btn.style.backgroundPosition = 'center';
btn.classList.add('website-icon');

btn.href = `https://nyaa.si/?f=${filter}&c=${category}&q=${titleJap}&s=${sort}&o=${order}`;
btn.target = '_blank';
}
}
}, 50);
break;
}

awaitLoadOf('.nyaaBtn').then(() => {
Expand All @@ -174,7 +224,8 @@ const searchNyaa = () => {
const hasSeason = /(?<![\w])(season)(?![\w])/i;
const hasNum = /(?<![\w])[0-9]+(?:st|[nr]d|th)(?![\w])/i;
const hasWord = /(?<![\w])(first|second|third|fourth|fifth|(the final|final))(?![\w])/i;
const hasPart = /(?<![\w])(part)(?![\w])/i;
const hasPart = /(?<![\w])(part )/i;
const hasEndPunc = /[?!.]$/;

if (baseJap.includes(': ') || baseJap.includes(' - ')) {
baseJap.includes(': ') && (baseJap = baseJap.split(': ').shift());
Expand All @@ -192,6 +243,10 @@ const searchNyaa = () => {
}
} else if (hasPart.test(baseJap)) {
baseJap = baseJap.split(/( part)/i).shift();
} else if (hasEndPunc.test(baseJap)) {
console.log('loldude');
let japEndPunc = baseJap.match(hasEndPunc)[0];
baseJap = baseJap.split(japEndPunc).shift();
}
}

Expand All @@ -211,6 +266,10 @@ const searchNyaa = () => {
}
} else if (hasPart.test(baseEng)) {
baseEng = baseEng.split(/( part)/i).shift();
} else if (hasEndPunc.test(baseEng)) {
console.log('OKAAAAAAAAAAAY DUDE');
let engEndPunc = baseEng.match(hasEndPunc)[0];
baseEng = baseEng.split(engEndPunc).shift();
}
}
};
Expand Down
5 changes: 3 additions & 2 deletions src/manifest-chrome.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Nyaa Linker",
"version": "1.1.1",
"version": "1.2.0",
"description": "Adds a button to Anime and Manga database websites that opens a relevant Nyaa search",
"manifest_version": 3,

Expand All @@ -13,7 +13,8 @@
"*://*.kitsu.io/*",
"*://*.anime-planet.com/*",
"*://*.animenewsnetwork.com/encyclopedia/*",
"*://*.anidb.net/*"
"*://*.anidb.net/*",
"*://*.livechart.me/*"
],
"js": ["main.js"]
}
Expand Down
5 changes: 3 additions & 2 deletions src/manifest-firefox.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Nyaa Linker",
"version": "1.1.1",
"version": "1.2.0",
"description": "Adds a button to Anime and Manga database websites that opens a relevant Nyaa search",
"manifest_version": 2,

Expand All @@ -13,7 +13,8 @@
"*://*.kitsu.io/*",
"*://*.anime-planet.com/*",
"*://*.animenewsnetwork.com/encyclopedia/*",
"*://*.anidb.net/*"
"*://*.anidb.net/*",
"*://*.livechart.me/*"
],
"js": ["main.js"]
}
Expand Down
15 changes: 9 additions & 6 deletions src/popup/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@
body {
background: var(--clrDark);
color: var(--clrLight);
width: max-content;
}

.container {
width: 275px;
margin: 0.5em 0.75em;
display: grid;
grid-template-columns: max-content max-content;
grid-gap: 2px;
margin: 2px 0 5px 2px;
text-align: right;
}

select {
width: 75%;
background: var(--clrAccent);
color: var(--clrDark);
margin-top: 0.1rem;
text-indent: 0.1rem;
margin-right: 2px;
text-indent: 2px;
width: 100%;
}

#save {
width: 100%;
background: var(--clrAccent);
color: var(--clrDark);
width: 100%;
}

0 comments on commit 7ad2774

Please sign in to comment.