Bug 1944416: Restore individual tabs from closed groups in closed windows r=dao,sessi...
[gecko.git] / browser / components / pagedata / TwitterPageData.sys.mjs
blob88b06098cb40aa4ce6b7dcb64ddc653e55109902
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /**
6  * Collects Twitter card (https://developer.twitter.com/en/docs/twitter-for-websites/)
7  * related data from a page.
8  */
9 export const TwitterPageData = {
10   /**
11    * Collects the twitter data from the page.
12    *
13    * @param {Document} document
14    *   The document to collect from
15    *
16    * @returns {PageData}
17    */
18   collect(document) {
19     let pageData = {};
21     let twitterTags = document.querySelectorAll("meta[name^='twitter:'");
23     for (let tag of twitterTags) {
24       // Strip "twitter:" from the property name.
25       let propertyName = tag.getAttribute("name").substring(8);
27       switch (propertyName) {
28         case "site":
29           pageData.siteName = tag.getAttribute("content");
30           break;
31         case "description":
32           pageData.description = tag.getAttribute("content");
33           break;
34         case "image":
35           pageData.image = tag.getAttribute("content");
36           break;
37       }
38     }
40     return pageData;
41   },