Skip to content

Commit

Permalink
Merge pull request kakaroto#975 from IsaacAbramowitz/display-in-VTT-f…
Browse files Browse the repository at this point in the history
…eats-pages

Display Feat in VTT button on the feat pages
  • Loading branch information
kakaroto authored Jun 17, 2022
2 parents 5ab3a0f + 7ad54f5 commit 16702b9
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ const SRC_FILES = {
...DNDBEYOND_PAGE_DEPS,
"src/dndbeyond/content-scripts/item.js",
],
dndbeyond_feat: [
...DNDBEYOND_PAGE_DEPS,
"src/dndbeyond/content-scripts/feat.js",
],
dndbeyond_monster: [
...DNDBEYOND_PAGE_DEPS,
"src/dndbeyond/base/spell.js",
Expand Down
13 changes: 13 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@
],
"all_frames": true
},
{
"matches": [
"*://*.dndbeyond.com/feats/*"
],
"css": [
"dist/beyond20.css"
],
"js": [
"libs/jquery-3.4.1.min.js",
"dist/dndbeyond_feat.js"
],
"all_frames": true
},
{
"matches": [
"*://*.dndbeyond.com/sources/*",
Expand Down
13 changes: 13 additions & 0 deletions manifest_ff.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@
],
"all_frames": true
},
{
"matches": [
"*://*.dndbeyond.com/feats/*"
],
"css": [
"dist/beyond20.css"
],
"js": [
"libs/jquery-3.4.1.min.js",
"dist/dndbeyond_feat.js"
],
"all_frames": true
},
{
"matches": [
"*://*.dndbeyond.com/sources/*",
Expand Down
96 changes: 96 additions & 0 deletions src/dndbeyond/content-scripts/feat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
console.log("Beyond20: D&D Beyond Feats module loaded.");

class FeatCharacter extends CharacterBase {
constructor(global_settings) {
super("feat", global_settings);
}
getDict() {
const dict = super.getDict();
if (this.avatar) {
dict.avatar = this.avatar;
}
return dict;
}
}

var character = null;
var settings = getDefaultSettings();

function addDisplayFeatButton() {
const icon32 = chrome.runtime.getURL("images/icons/badges/normal32.png");
const button = E.a({ class: "ct-beyond20-roll button-alt", href: "#" },
E.span({ class: "label" }, "Display Feat on VTT")
);
const feat_name = $(".page-title").text().trim();
const sourceType = "Feat";
const description = descriptionToString(".details-container-feat .details-container-content-description").trim();
const feat_tags = $(".details-container-content-footer .tags .tag").toArray().map(elem => elem.textContent);
$(".page-heading__content").after(button);

$(".ct-beyond20-roll").css({
"float": "right",
"display": "inline-block"
});
$(".ct-beyond20-roll").on('click', (event) => {
sendRoll(character, "feature", 0, {
"name": feat_name,
"source-type": sourceType,
"description": description,
"tags": feat_tags
});
}
);
}

function documentLoaded(settings) {
cleanupAlertifyComments();
character = new FeatCharacter(settings);
if (isRollButtonAdded()) {
chrome.runtime.sendMessage({ "action": "reload-me" });
} else {
addDisplayFeatButton();
const avatar = $(".details-container-aside .image-container img");
if (avatar.length > 0) {
character.avatar = avatar[0].src;
const avatarImg = $(".details-container-aside .image-container");
if (avatarImg) {
addDisplayButton(() => {
sendRoll(character, "avatar", character.avatar, { "name": "Feat" });
}, avatarImg, { small: false, image: true });
}
}
const feat_name = $(".page-title").text().trim();
if (settings['subst-dndbeyond'])
injectDiceToRolls(".details-container-feat .details-container-content-description", character, feat_name);
}
}

function updateSettings(new_settings = null) {
if (new_settings) {
settings = new_settings;
if (character)
character.setGlobalSettings(new_settings);
key_bindings = getKeyBindings(settings)
} else {
getStoredSettings((saved_settings) => {
documentLoaded(saved_settings);
updateSettings(saved_settings);
});
}
}

function handleMessage(request, sender, sendResponse) {
if (request.action == "settings") {
if (request.type == "general")
updateSettings(request.settings);
} else if (request.action == "open-options") {
alertFullSettings();
}
}

injectCSS(BUTTON_STYLE_CSS);
chrome.runtime.onMessage.addListener(handleMessage);
chrome.runtime.sendMessage({ "action": "activate-icon" });
updateSettings();


0 comments on commit 16702b9

Please sign in to comment.