tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

changes-utils.js (1309B)


      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/. */
      4 
      5 "use strict";
      6 
      7 const {
      8  getStr,
      9 } = require("resource://devtools/client/inspector/changes/utils/l10n.js");
     10 
     11 /**
     12 * Get a human-friendly style source path to display in the Changes panel.
     13 * For element inline styles, return a string indicating that.
     14 * For inline stylesheets, return a string indicating that.
     15 * For URLs, return just the stylesheet filename.
     16 *
     17 * @param {object} source
     18 *        Information about the style source. Contains:
     19 *        - type: {string} One of "element" or "stylesheet"
     20 *        - href: {String|null} Stylesheet URL or document URL for elmeent inline styles
     21 * @return {string}
     22 */
     23 function getSourceForDisplay(source) {
     24  let href;
     25 
     26  switch (source.type) {
     27    case "element":
     28      href = getStr("changes.elementStyleLabel");
     29      break;
     30    case "inline":
     31      href = getStr("changes.inlineStyleSheetLabel2");
     32      break;
     33    case "stylesheet": {
     34      const url = new URL(source.href);
     35      href = url.pathname.substring(url.pathname.lastIndexOf("/") + 1);
     36      break;
     37    }
     38  }
     39 
     40  return href;
     41 }
     42 
     43 module.exports.getSourceForDisplay = getSourceForDisplay;