File: options.js

package info (click to toggle)
allow-html-temp 10.0.8-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 368 kB
  • sloc: javascript: 1,454; makefile: 25; sh: 7
file content (108 lines) | stat: -rw-r--r-- 3,269 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var options = {};

async function optionsMigrate() {
  // Because of old LegacyPrefs using other value then the new options system, we can't do a simple recursion for the 3 LegacyPrefs.
  // Therefore the following procedures (only) seem to be redundant.

  let legacyName = "";
  let legacyValue = null;

  legacyName = "extensions.allowHtmlTemp.ButtonFunction";
  legacyValue = null;
  legacyValue = await messenger.LegacyPrefs.getUserPref(legacyName);

  if (legacyValue !== null) {
    console.log("Migrating legacy preference: " + legacyName + " = ", legacyValue);

    // Migrate old integer value to new string value
    // Sometimes, there is a strange issue leading to string vs integer values. Get both in the switch:
    switch (legacyValue) {
      case 0:
        newValue = "buttonMode_html";
        break;
      case "0":
        newValue = "buttonMode_html";
        break;
      case 1:
        newValue = "buttonMode_sanitized";
        break;
      case "1":
        newValue = "buttonMode_sanitized";
        break;
      case 2:
        newValue = "buttonMode_plaintext";
        break;
      case "2":
        newValue = "buttonMode_plaintext";
        break;
    }
    messenger.storage.local.set({
      buttonHtmlMode: newValue
    });

    // Clear the legacy value.
    messenger.LegacyPrefs.clearUserPref(legacyName);
  }

  legacyName = "extensions.allowHtmlTemp.ForceRemoteContent";
  legacyValue = null;
  legacyValue = await messenger.LegacyPrefs.getUserPref(legacyName);
  if (legacyValue !== null) {
    console.log("Migrating legacy preference: " + legacyName + " = ", legacyValue);

    messenger.storage.local.set({
      tempRemoteContent: legacyValue
    });

    // Clear the legacy value.
    messenger.LegacyPrefs.clearUserPref(legacyName);
  }

  legacyName = "extensions.allowHtmlTemp.InlineAttachmentsTemp";
  legacyValue = null;
  legacyValue = await messenger.LegacyPrefs.getUserPref(legacyName);
  if (legacyValue !== null) {
    console.log("Migrating legacy preference: " + legacyName + " = ", legacyValue);

    messenger.storage.local.set({
      tempInline: legacyValue
    });

    // Clear the legacy value.
    messenger.LegacyPrefs.clearUserPref(legacyName);
  }

  // Clear 2 more old legacy prefs
  messenger.LegacyPrefs.clearUserPref("extensions.allowHtmlTemp.JavaScriptTemp");
  messenger.LegacyPrefs.clearUserPref("extensions.allowHtmlTemp.reset_javascript_default_done_once");
}


async function optionsInit() {
  await reloadAllOptions();
}

async function reloadAllOptions() {
  await reloadOption("debug");
  await reloadOption("commandKey");
  await reloadOption("buttonHtmlMode");
  await reloadOption("tempRemoteContent");
  await reloadOption("tempInline");
}

function reloadOption(id) {
  return messenger.storage.local.get(id).then((res) => {
    if (res[id] != undefined)
      options[id] = res[id];
    else
      options[id] = DefaultOptions[id];
  }, defaultError);
}

async function getOption(name) {
  if (!DefaultOptions[name]) {
    throw new Error(`Unknown option ${name}`)
  }
  let rv = await messenger.storage.local.get({[name]: DefaultOptions[name]});
  return rv[name];
}