summaryrefslogtreecommitdiff
path: root/ext/fg/js/float.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-06 18:55:36 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-06 18:55:36 -0400
commit696897f6fa431c0c24332c5dd2a2c12a07923c0e (patch)
tree3216fa4998d8500760116381bbebde9456982036 /ext/fg/js/float.js
parent199b926f239ddf64c95f23415851a11ba4bf7c2a (diff)
Add support for getting the document title
Diffstat (limited to 'ext/fg/js/float.js')
-rw-r--r--ext/fg/js/float.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 9b720ebe..01055ca6 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -162,6 +162,33 @@ class DisplayFloat extends Display {
setContentScale(scale) {
document.body.style.fontSize = `${scale}em`;
}
+
+ async getDocumentTitle() {
+ try {
+ const uniqueId = yomichan.generateId(16);
+
+ const promise = yomichan.getTemporaryListenerResult(
+ chrome.runtime.onMessage,
+ ({action, params}, {resolve}) => {
+ if (
+ action === 'documentInformationBroadcast' &&
+ isObject(params) &&
+ params.uniqueId === uniqueId &&
+ params.frameId === 0
+ ) {
+ resolve(params);
+ }
+ },
+ 2000
+ );
+ apiForward('requestDocumentInformationBroadcast', {uniqueId});
+
+ const {title} = await promise;
+ return title;
+ } catch (e) {
+ return '';
+ }
+ }
}
DisplayFloat.instance = new DisplayFloat();