...
 
Commits (10)
.idea/
*.iml
\ No newline at end of file
*.iml
node_modules/
package-lock.json
web-ext-artifacts/
\ No newline at end of file
stages:
- stats
- test
- build
- sign
- release
gitstats:
stage: stats
......@@ -10,3 +14,51 @@ gitstats:
script:
- python3 -m venv virtual && source virtual/bin/activate && pip install ci-scripts
- gitstats-gen
lint:
stage: test
tags:
- python3
- npm
script:
- python3 -m venv virtual && source virtual/bin/activate && pip install ci-scripts
- webext-lint
build_addon:
stage: build
tags:
- python3
- npm
script:
- python3 -m venv virtual && source virtual/bin/activate && pip install ci-scripts
- webext-build
artifacts:
expire_in: 1 week
paths:
- artifacts/
sign_addon:
stage: build
only:
- master
tags:
- python3
- npm
script:
- python3 -m venv virtual && source virtual/bin/activate && pip install ci-scripts
- webext-build --signed
artifacts:
expire_in: 1 week
paths:
- artifacts/
release_upload:
stage: release
only:
- master
tags:
- python3
script:
- python3 -m venv virtual && source virtual/bin/activate && pip install ci-scripts
- github-release-upload $(webext-version) "$(changelog-reader)"
- gitlab-release-upload $(webext-version) "$(changelog-reader)"
# This file was created by https://github.com/mozilla/web-ext
# Your auto-generated extension ID for addons.mozilla.org is:
{31a6d06d-fc84-46a4-b37a-3bf5439cc131}
\ No newline at end of file
V 0.1.0:
- Initial Release
\ No newline at end of file
# Contributing
## Copyright and Management
The original author, Hermann Krumrey, has the absolute authority on the management
of this project and may steer the development process as he sees fit.
Contributions will be attributed to the author of said code and the copyright will
remain the author's.
## Contributing
All active development is done on a [self-hosted Gitlab server](https://gitlab.namibsun.net).
To contribute, send an email to hermann@krumreyh.com to create an account. Once you have an
account, you may issue a merge or pull request.
Using the Gitlab issue tracker is preferred, but the issues on Github are also
taken into consideration.
\ No newline at end of file
# anilist-enhancer
[![pipeline status](https://gitlab.namibsun.net/namibsun/anilist-enhancer/badges/master/pipeline.svg)](https://gitlab.namibsun.net/namibsun/anilist-enhancer/commits/master)
|master|develop|
|:----:|:-----:|
|[![build status](https://gitlab.namibsun.net/namibsun/python/anilist-enhancer/badges/master/build.svg)](https://gitlab.namibsun.net/namibsun/python/anilist-enhancer/commits/master)|[![build status](https://gitlab.namibsun.net/namibsun/python/anilist-enhancer/badges/develop/build.svg)](https://gitlab.namibsun.net/namibsun/python/anilist-enhancer/commits/develop)|
![Logo](resources/logo/logo-readme.png)
A firefox extension that adds additional information to an anilist.co page
A firefox extension that adds additional information to an anilist.co page.
Currently, the following elements are added to anime and manga pages:
* anilist.co button
* myanimelist.net button
## Further Information
......
{
"description": "A firefox extension that adds additional information to an anilist.co page",
"version": "0.1.0",
"manifest_version": 2,
"name": "anilist-enhancer",
"version": "1.0",
"description": "A firefox extension that adds additional information to an anilist.co page",
"homepage_url": "https://gitlab.namibsun.net:/namibsun/anilist-enhancer",
"icons": {
......@@ -13,9 +12,12 @@
"content_scripts": [
{
"matches": ["*://anilist.co/anime/*", "*://anilist.co/manga/*", "*://google.com/*"],
"matches": ["*://anilist.co/anime/*", "*://anilist.co/manga/*"],
"js": ["src/anilist-enhancer.js"]
}
]
],
"permissions": [
"*://graphql.anilist.co/*"
]
}
\ No newline at end of file
......@@ -17,25 +17,98 @@ You should have received a copy of the GNU General Public License
along with anilist-enhancer. If not, see <http://www.gnu.org/licenses/>.
*/
document.root = null;
var anilistId = 1;
var malId = getMalId(anilistId);
var malUrl = "https://myanimelist.net/anime/" + malId
console.log(malUrl)
function getMalId(anilistId) {
var query = `
query ($id: Int) {
Media (id: $id, type: ANIME) {
idMal
}
}
`;
var variables = {id: anilistId}
var url = 'https://graphql.anilist.co';
var options = {
/**
* Runs the main script every 100ms until stopped
* @type {number} The interval number
*/
setInterval(main, 500);
let url = window.location.href;
/**
* The main function of this script
*/
function main() {
if (document.getElementsByClassName("data").length === 0) {
// Continue
}
else if (document.getElementById("anilist-enhancer-table") === null) {
loadData();
}
else if (url !== window.location.href) {
url = window.location.href;
document.getElementsByClassName("sidebar")[0].removeChild(
document.getElementById("anilist-enhancer-table")
);
loadData();
}
}
/**
* Loads the data into the sidebar
*/
function loadData() {
prepare();
const anilistId = getAnilistId();
displayButton(anilistId, "", "/img/icons/icon.svg");
displayMyanimelistData(anilistId, getAnilistType());
}
/**
* Prepares divs for the new data
*/
function prepare() {
let buttonTable = document.createElement("table");
buttonTable.id = "anilist-enhancer-table";
buttonTable.style.textAlign = "center";
buttonTable.style.width = "100%";
buttonTable.style.marginBottom = "15px";
const beforeButtons = document.getElementsByClassName("sidebar")[0].children[0];
document.getElementsByClassName("sidebar")[0].insertBefore(buttonTable, beforeButtons);
}
/**
* Retrieves the anilist ID of the page
* @returns {number} The anilist ID
*/
function getAnilistId() {
const url = window.location.href;
return Number(url.split("https://anilist.co/")[1].split("/")[1])
}
/**
* Retrieves the anilist type, either anime or manga
* @returns {string} The anilist entry type
*/
function getAnilistType() {
const url = window.location.href;
return url.split("https://anilist.co/")[1].split("/")[0]
}
/**
* Displays myanimelist.net information in the data section
* @param anilistId {Number} The anilist ID
* @param anilistType {String} The anilist media type
*/
function displayMyanimelistData(anilistId, anilistType) {
const url = 'https://graphql.anilist.co';
let query = `
query ($id: Int) {
Media (id: $id, type: ANIME) {
idMal
}
}
`;
const variables = {id: anilistId};
if (anilistType === "manga") {
query = query.replace("ANIME", "MANGA")
}
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
......@@ -47,11 +120,56 @@ function getMalId(anilistId) {
})
};
return fetch(url, options)
.then(function(response) {
return response.json();
})
.then(function(json) {
return json["data"]["Media"]["idMal"]
});
fetch(url, options)
.then(function handleResponse(response) {
return response.json().then(function (json) {
return response.ok ? json : Promise.reject(json);
});
})
.then(function handleData(data) {
if (data["data"] !== null) {
const malId = data["data"]["Media"]["idMal"];
if (malId !== null) {
const malUrl = "https://myanimelist.net/" + anilistType + "/" + malId;
const malImg = "https://pbs.twimg.com/profile_images/926302376738377729/SMlpasPv.jpg";
displayButton(malId, malUrl, malImg);
}
}
})
.catch(function handleError(error) {
console.error(error);
});
}
/**
* Shows the a button on the side bar
* @param id {Number} The ID to display
* @param url {String} The URL to which to link to
* @param imgUrl {String} The URL linking to the image for the button
*/
function displayButton(id, url, imgUrl) {
let entry = document.createElement("tr");
let imageCol = document.createElement("td");
let idCol = document.createElement("td");
let buttonLink = document.createElement("a");
buttonLink.href = url;
let buttonImg = document.createElement('img');
buttonImg.src = imgUrl;
buttonImg.width = 50;
buttonImg.height = 50;
buttonImg.style.background = "black";
let idText = document.createTextNode(id.toString());
buttonLink.appendChild(buttonImg);
imageCol.appendChild(buttonLink);
idCol.appendChild(idText);
entry.appendChild(imageCol);
entry.appendChild(idCol);
document.getElementById("anilist-enhancer-table").appendChild(entry);
}