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

Added rol20 template cards #125

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 0 additions & 4 deletions .babelrc.js

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ typings/
# Parcel related files
dist/
.cache/
.parcel-cache/

# Editor configuration
.vscode/
Expand Down
14 changes: 14 additions & 0 deletions config.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>

<input type ="text" id="discordurl" name="discordurl" value="Webookurl">

<div id="status"></div>
<button id="save">Save</button>

</body>
<script src="config.js"></script>
</html>
30 changes: 30 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Saves options to chrome.storage
function save_options() {
var discordurl = document.getElementById('discordurl').value;
chrome.storage.sync.set({
discordurl: discordurl
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
console.debug('Saved as: ' + discordurl);
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 750);
});
}

// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
chrome.storage.sync.get({
discordurl: ''
}, function(items) {
document.getElementById('discordurl').value = items.discordurl;
console.debug('Loaded: ' + discordurl);
});
}


document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click',save_options);
32 changes: 26 additions & 6 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
{
"manifest_version": 2,
"manifest_version": 3,
"name": "VTT Bridge",
"version": "1.6.3",

"version": "1.6.4",
"browser_specific_settings": {
"gecko": {
"id": "[email protected]"
}
},
"description": "Connect Dungeon Master's Vault to Roll20.",


"background": {
"service_worker": "wrapper.js",
"type": "module"
},
"icons": {
"48": "icons/48.png",
"96": "icons/96.png",
"128": "icons/128.png"
},
"permissions": [
"storage"
],
"options_ui": {
"page": "config.html",
"open_in_tab": false
},
"browser_action": {
"default_popup": "config.html"
},
"content_scripts": [
{
"matches": ["*://www.dungeonmastersvault.com/pages/dnd/5e/characters/*?frame=true"],
Expand All @@ -19,8 +41,6 @@
"js": ["dist/polyfill.js", "dist/roll20.js"],
"css": ["dist/roll20.css"]
}
],
"background": {
"scripts": ["dist/polyfill.js", "dist/background.js"]
}
]

}
39 changes: 22 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,34 @@
"name": "vtt-bridge",
"description": "Connect Dungeon Master's Vault to Roll20.",
"author": "Avery Crespi",
"version": "1.6.3",
"version": "1.6.4",
"license": "MIT",
"dependencies": {
"beedle": "^0.8.1",
"notyf": "^3.6.0"
"node": "^19.4.0",
"notyf": "^3.10.0"
},
"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/plugin-transform-runtime": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"babel-jest": "^26.0.1",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-jest": "^23.9.0",
"eslint-plugin-prettier": "^3.1.2",
"jest": "^26.0.1",
"parcel-bundler": "^1.12.4",
"prettier": "^2.0.2",
"web-ext": "^4.2.0",
"webextension-polyfill": "^0.6.0"
"@babel/core": "^7.20.12",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"babel-jest": "^29.4.0",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.4.0",
"parcel": "^2.8.3",
"prettier": "^2.8.3",
"web-ext": "^7.5.0",
"webextension-polyfill": "^0.10.0",
"yarn-upgrade-all": "^0.7.2"
},
"scripts": {
"parcel:polyfill": "mkdir -p dist/ && cp node_modules/webextension-polyfill/dist/browser-polyfill.min.js dist/polyfill.js",
"parcel:build": "yarn parcel:polyfill && parcel build --no-source-maps src/scripts/*",
"parcel:watch": "yarn parcel:polyfill && parcel watch --no-source-maps src/scripts/*",
"parcel:clean": "rm -rf dist/*",
"parcel:clean": "rm -rf disty/*",
"parcel:rebuild": "yarn parcel:clean && yarn parcel:build",
"parcel:test": "jest",
"assets:optimize": "optipng assets/*",
Expand Down Expand Up @@ -55,7 +57,10 @@
"keepProfileChanges": true,
"firefoxProfile": ".profiles/firefox",
"chromiumProfile": ".profiles/chromium",
"watchFile": "dist/dmv.js",
"watchFile": [
"dist/dmv.js",
""
],
"startUrl": [
"https://www.dungeonmastersvault.com/pages/dnd/5e/characters",
"https://app.roll20.net"
Expand Down
19 changes: 18 additions & 1 deletion src/dispatch/expandSpell.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ const ready = (store) => {
}

const cell = button.closest("td");

//Get spell details as array
const div = Array.from(cell.querySelectorAll("div"));
const spellItems = (div[0].innerText).split("\n");

const index = spellItems.indexOf("CAST SPELL");//Rip out all the different cast levels
spellItems.splice(0,index +1);


console.debug(`Added expand spell items: ${spellItems}`);

/*const school = items[3];
const castingTime = items[4];
const range = items[5];
const duration = items[6];
const components = items[7];
*/
const paragraphs = Array.from(cell.querySelectorAll("p"));
const description = paragraphs.map((p) => p.innerText).join("\n");
if (!isValidDescription(description)) {
Expand All @@ -35,7 +52,7 @@ const ready = (store) => {
}

button.addEventListener("click", function (event) {
store.dispatch(STORE_CLICK, { className, event, data: { name, description } });
store.dispatch(STORE_CLICK, { className, event, data: { name, description, spellItems } });
});

console.debug(`Added expand spell listener: ${name}`);
Expand Down
15 changes: 10 additions & 5 deletions src/dispatch/weapon.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ const ready = (store) => {
}

attackButton.classList.add(classes.attackWithWeapon);
attackButton.addEventListener("click", function (event) {
store.dispatch(STORE_CLICK, { className: classes.attackWithWeapon, event, data: { name, attack } });
});
console.debug(`Added weapon attack listener: ${name}`);



for (const damageButton of damageButtons) {
let damage = damageButton.innerText;
if (damage.charAt(0) === "v") {
Expand All @@ -47,6 +44,14 @@ const ready = (store) => {
}

damageButton.classList.add(classes.rollWeaponDamage);


attackButton.addEventListener("click", function (event) {
store.dispatch(STORE_CLICK, { className: classes.attackWithWeapon, event, data: { name, attack, damage } });
});

console.debug(`Added weapon attack listener: ${name}`);

damageButton.addEventListener("click", function (event) {
store.dispatch(STORE_CLICK, { className: classes.rollWeaponDamage, event, data: { name, damage } });
});
Expand Down
27 changes: 27 additions & 0 deletions src/scripts/discord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export function sendMessage(message) {
chrome.storage.sync.get("discordurl", function (items) {
if (!chrome.runtime.error) {
console.debug('Loaded: URL as' + items.discordurl);
const character = document.querySelector(".character-name").innerText
const request = new XMLHttpRequest();
request.open("POST", items.discordurl);

request.setRequestHeader('Content-type', 'application/json');

const params = {
username: "DMZ-Bot",
avatar_url: "https://github.com/Garemat/vtt-bridge/blob/main/icons/128.png?raw=true",
content: null,
embeds: [
{
title: character,
description: character + " has made a " + message
}
]

}

request.send(JSON.stringify(params));
}
});
}
42 changes: 42 additions & 0 deletions src/scripts/dmv.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createStore } from "../store";
import { formatError } from "../transform/error";
import { messageType } from "../common";
import { parseState } from "../transform/state";
import { sendMessage } from "./discord";

const store = createStore();
addDispatchers(store, () => showConnected());
Expand All @@ -28,3 +29,44 @@ store.subscribe((state) => {
console.debug(`Showed visibility toast: ${JSON.stringify(state.visible)}`);
}
});

function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}

const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
});

observer.observe(document.body, {
childList: true,
subtree: true
});
});
}

waitForElm('.bg-green').then((elm) => {
console.log('Element is ready');
console.log(elm.textContent);
var mutationObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.target.textContent);
sendMessage(mutation.target.textContent)
});
});
mutationObserver.observe(document.querySelector('.bg-green'), {
attributes: true,
characterData: true,
childList: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true
});

});

Loading