forked from kakaroto/Beyond20
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kakaroto#975 from IsaacAbramowitz/display-in-VTT-f…
…eats-pages Display Feat in VTT button on the feat pages
- Loading branch information
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
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
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(); | ||
|
||
|