Skip to content

Commit

Permalink
Storage the checkbox state. #3
Browse files Browse the repository at this point in the history
1.2.0
  • Loading branch information
zeteticl committed Sep 11, 2021
1 parent 8252192 commit 6c01262
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Specify the identity of the speaker, no longer based on the selected token

## Changelog

### v1.2.0

Storage the checkbox state.

### v1.1.5

Get the style by js.
Expand Down
36 changes: 31 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
var color;
var height;
var bgcolor;
var width;
var width = "80%";;

Hooks.once('init', () => {
//Not used anymore but kept for compatibility with migration
game.settings.register("speak-as", "checked", {
name: "checked",
scope: "client",
default: true,
type: Boolean,
config: false
});

});

Hooks.once('ready', () => {
const btn = document.querySelector('#speakerSwitch');
btn.addEventListener('click', (event) => {
let checked = document.getElementById("speakerSwitch").checked;
game.settings.set("speak-as", "checked", checked)
});
});
Hooks.on("renderSidebarTab", (dialog, $element, targets) => {
/**
* 自己的登入名字
Expand All @@ -14,7 +34,7 @@ Hooks.on("renderSidebarTab", (dialog, $element, targets) => {
$(".roll-type-select").css("color") ? color = $(".roll-type-select").css("color") : null;
$(".roll-type-select").css("height") ? height = $(".roll-type-select").css("height") : null;
$(".roll-type-select").css("background") ? bgcolor = $(".roll-type-select").css("background") : null;
$(".roll-type-select").css("width") ? width = $(".roll-type-select").css("width") : null;
check();

var x = document.querySelectorAll("#namelist");
if (width) x[0].style.setProperty("width", width, "important")
Expand All @@ -33,7 +53,7 @@ function updateSpeakerList() {
let selectedCharacter = myactors.find(actor => actor.id === myUser.character?.id);

let addText = `<div style="flex: 0;" id="divnamelist">
<input type="checkbox" id="speakerSwitch" name="speakerSwitch" checked>
<input type="checkbox" id="speakerSwitch" name="speakerSwitch" checked>
<select name="namelist" id="namelist" class="namelist">
<optgroup label="Speak As....">`;
if (selectedCharacter) addText += `<option value="${selectedCharacter.id}">${selectedCharacter.name}</option>`
Expand Down Expand Up @@ -78,19 +98,25 @@ Hooks.on("chatMessage", (dialog, $element, targets) => {
Hooks.on("renderActorDirectory", (dialog, $element, targets) => {
$('#divnamelist').remove();
$('#chat-controls.flexrow').before(updateSpeakerList());

check()

$(".roll-type-select").css("color") ? color = $(".roll-type-select").css("color") : null;
$(".roll-type-select").css("height") ? height = $(".roll-type-select").css("height") : null;
$(".roll-type-select").css("background") ? bgcolor = $(".roll-type-select").css("background") : null;
$(".roll-type-select").css("width") ? width = $(".roll-type-select").css("width") : null;
var x = document.querySelectorAll("#namelist");
if (width) x[0].style.setProperty("width", width, "important")
if (color) x[0].style.setProperty("color", color, "important")
if (height) x[0].style.setProperty("height", height, "important")
if (bgcolor) x[0].style.setProperty("background", bgcolor, "important")
});

function check() {
let checked = game.settings.get("speak-as", "checked")
document.getElementById("speakerSwitch").checked = checked;
}




//targets.speaker.token = "XXX"
//2)如場上有同樣的TOKEN,使用那個TOKEN發言
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"authors": [],
"url": "https://github.com/hktrpg/foundryVTT-speak-as",
"flags": {},
"version": "1.1.5",
"version": "1.2.0",
"minimumCoreVersion": "0.8.9",
"compatibleCoreVersion": "0.8.9",
"scripts": [
Expand Down

0 comments on commit 6c01262

Please sign in to comment.