Permalink
Browse files

Allow syncing of certain Scriptish options using the Firefox Sync ser…

…vice. Closes #14
  • Loading branch information...
1 parent 8507967 commit 70523133db41ab0617fee76fb2f1c7e889be1d9c @supahgreg supahgreg committed Sep 22, 2012
View
71 extension/content/js/options.js
@@ -4,6 +4,7 @@ Components.utils.import("resource://scriptish/constants.js");
lazyImport(this, "resource://scriptish/config.js", ["Scriptish_config"]);
lazyImport(this, "resource://scriptish/scriptish.js", ["Scriptish"]);
+lazyImport(this, "resource://scriptish/prefmanager.js", ["Scriptish_prefRoot", "Scriptish_PrefManager"]);
lazyImport(this, "resource://scriptish/utils/Scriptish_localizeDOM.js", ["Scriptish_localizeOnLoad"]);
lazyImport(this, "resource://scriptish/utils/Scriptish_isURLExcluded.js", [
"Scriptish_isURLExcluded",
@@ -16,6 +17,8 @@ lazyUtil(this, "getEditor");
lazyUtil(this, "sendAsyncE10SMessage");
lazyUtil(this, "stringBundle");
+const RE_scriptishPrefix = /^extensions\.scriptish\./;
+
function $(aID) document.getElementById(aID);
function changeEditor() Scriptish_getEditor(window, true);
@@ -27,6 +30,65 @@ function saveExcludes() {
Scriptish.notify(null, "scriptish-preferences-change", true);
}
+function checkSync() {
+ let Scriptish_SyncManager = new Scriptish_PrefManager(null, true);
+ let prefSyncEnabled;
+
+ try {
+ prefSyncEnabled = Services.prefs.getBoolPref("services.sync.engine.prefs");
+ }
+ catch(e) {
+ prefSyncEnabled = false;
+ }
+
+ // Do nothing if pref syncing isn't enabled
+ if (!prefSyncEnabled) {
+ return;
+ }
+
+ // Sync "common" preferences?
+ let syncCommonPrefName = "sync.ScriptishPrefs.common";
+ let syncCommon = Scriptish_prefRoot.getValue(syncCommonPrefName, false);
+
+ // Sync the editor preference?
+ let syncEditorPrefName = "sync.ScriptishPrefs.editor";
+ let syncEditor = Scriptish_prefRoot.getValue(syncEditorPrefName, false);
+
+ // Collect preferences used in Options... considering these "common" prefs.
+ // Others can be added to the prefNames array as needed.
+ let prefNodes = document.getElementsByTagName("preference");
+ let prefNames = [];
+ for (let i = 0, e = prefNodes.length; i < e; ++i) {
+ prefNames.push(prefNodes[i].name.replace(RE_scriptishPrefix, ""));
+ }
+
+ // Exclude the sync-controlling preferences
+ let syncCommonIndex = prefNames.indexOf(syncCommonPrefName);
+ if (syncCommonIndex > -1) prefNames.splice(syncCommonIndex, 1);
+
+ let syncEditorIndex = prefNames.indexOf(syncEditorPrefName);
+ if (syncEditorIndex > -1) prefNames.splice(syncEditorIndex, 1);
+
+ // Exclude the editor pref from the general list. The editor is handled
+ // separately since the path might vary between systems.
+ let editorIndex = prefNames.indexOf("editor");
+ if (editorIndex > -1) prefNames.splice(editorIndex, 1);
+
+ // Either sync or unsync all eligible preferences
+ let syncOp =
+ (syncCommon ? Scriptish_SyncManager.sync : Scriptish_SyncManager.unsync)
+ .bind(Scriptish_SyncManager);
+ for (let i = 0, e = prefNames.length; i < e; ++i) {
+ syncOp(prefNames[i]);
+ }
+
+ // Either sync or unsync the editor preference
+ syncOp =
+ (syncEditor ? Scriptish_SyncManager.sync : Scriptish_SyncManager.unsync)
+ .bind(Scriptish_SyncManager);
+ syncOp("editor");
+}
+
Scriptish_localizeOnLoad(this);
addEventListener("load", function init() {
@@ -43,4 +105,13 @@ addEventListener("load", function init() {
else {
addEventListener("dialogaccept", saveExcludes, true);
}
+
+ // Check sync options to determine whether to add or remove sync service vals.
+ // NOTE: Delaying to allow the sync-controlling prefs to update.
+ if (instantApply) {
+ addEventListener("unload", function() { timeout(checkSync) }, false);
+ }
+ else {
+ addEventListener("dialogaccept", function() { timeout(checkSync) }, true);
+ }
}, false);
View
15 extension/content/options.xul
@@ -81,6 +81,21 @@
</hbox>
</prefpane>
+ <prefpane id="pane-sync" label="sync" localize="label">
+ <preferences>
+ <preference id="pref-syncScriptishPrefsCommon" name="extensions.scriptish.sync.ScriptishPrefs.common" type="bool"/>
+ <preference id="pref-syncScriptishPrefsEditor" name="extensions.scriptish.sync.ScriptishPrefs.editor" type="bool"/>
+ </preferences>
+
+ <description value="options.sync.desc" localize="value"/>
+
+ <groupbox>
+ <caption label="options.sync.ScriptishPrefs" localize="label"/>
+ <checkbox id="sync-common" preference="pref-syncScriptishPrefsCommon" label="options.sync.ScriptishPrefs.common" localize="label"/>
+ <checkbox preference="pref-syncScriptishPrefsEditor" label="options.sync.ScriptishPrefs.editor" localize="label"/>
+ </groupbox>
+ </prefpane>
+
<prefpane id="pane-advanced" label="options.pane.advanced" localize="label">
<preferences>
<preference id="pref-cache-enabled" name="extensions.scriptish.cache.enabled" type="bool"/>
View
2 extension/defaults/preferences/scriptish.js
@@ -20,6 +20,8 @@ pref("extensions.scriptish.enableScriptRefreshing", true);
pref("extensions.scriptish.logChrome", false);
pref("extensions.scriptish.logToErrorConsole", true);
pref("extensions.scriptish.optimizingRegexpMerge", false);
+pref("extensions.scriptish.sync.ScriptishPrefs.common", false);
+pref("extensions.scriptish.sync.ScriptishPrefs.editor", false);
pref("extensions.scriptish.toolbarbutton.showScripts", true);
pref("extensions.scriptish.uninstallPreferences", true);
pref("extensions.scriptish.update.requireBuiltInCerts", true);
View
5 extension/locale/de/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=Allgemein
options.pane.ui=Benutzeroberfläche
options.requireBuiltInCerts=Sichere Aktualisierungen müssen eingebaute Zertifikate nutzen
options.requireSecured=Benutzerskripte müssen über eine sichere Verbindung (https) aktualisiert werden
+options.sync.desc=
+options.sync.ScriptishPrefs=
+options.sync.ScriptishPrefs.common=
+options.sync.ScriptishPrefs.editor=
options.title=Scriptish Einstellungen
options.toolbarbutton=Toolbar Button
options.toolbarbutton.showScripts=Anzahl aktiver Skripte zeigen
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=Seite ist ausgenommen!
statusbar.noScripts.notfound=Keine Benutzerskripte für diese Seite!
statusbar.noScripts.scheme=Protokoll ist deaktiviert!
statusbar.updated=erfolgreich aktualisiert
+sync=
tooltip.loading=Lade...
Uninstall=Entfernen
untitledScript=Unbenanntes Script
View
5 extension/locale/en-US/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=Main
options.pane.ui=User Interface
options.requireBuiltInCerts=Secure update requires using built-in certificates
options.requireSecured=Require user scripts to update using HTTPS
+options.sync.desc=The Firefox Sync service and its "Preferences" option must be enabled!
+options.sync.ScriptishPrefs=Scriptish Preferences
+options.sync.ScriptishPrefs.common=Synchronize common Scriptish extension preferences
+options.sync.ScriptishPrefs.editor=Synchronize the Editor preference
options.title=Scriptish Options
options.toolbarbutton=Toolbar button
options.toolbarbutton.showScripts=Show active script count
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=Page is excluded!
statusbar.noScripts.notfound=No scripts for page!
statusbar.noScripts.scheme=Scheme is disabled!
statusbar.updated=updated successfully
+sync=Sync
tooltip.loading=Loading...
Uninstall=Uninstall
untitledScript=Untitled Script
View
5 extension/locale/es-ES/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=Principal
options.pane.ui=Interfaz de usuario
options.requireBuiltInCerts=Las actualizaciones seguras requieren que el certificado esté incluído
options.requireSecured=Requerir que los scripts de usuario se actualicen usando HTTPS
+options.sync.desc=
+options.sync.ScriptishPrefs=
+options.sync.ScriptishPrefs.common=
+options.sync.ScriptishPrefs.editor=
options.title=Opciones de Scriptish
options.toolbarbutton=Botón de la Barra de Herramientas
options.toolbarbutton.showScripts=Muestra la cuenta de scripts activos
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=¡Esta página está excluída!
statusbar.noScripts.notfound=¡No hay scripts para esta página!
statusbar.noScripts.scheme=¡Este patrón está deshabilitado!
statusbar.updated=actualizado con éxito
+sync=
tooltip.loading=Cargando...
Uninstall=Desinstalar
untitledScript=Script sin título
View
5 extension/locale/he/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=ראשי
options.pane.ui=ממשק
options.requireBuiltInCerts=עדכון מאובטח מחייב שימוש באישורים מובנים
options.requireSecured=דרוש מקבצי script של משתמש להתעדכן ע"י שימוש ב־HTTPS
+options.sync.desc=
+options.sync.ScriptishPrefs=
+options.sync.ScriptishPrefs.common=
+options.sync.ScriptishPrefs.editor=
options.title=אפשרויות של Scriptish
options.toolbarbutton=לחצן סרגל כלים
options.toolbarbutton.showScripts=הצג את מספר ה־scripts הפעילים
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=הדף אינו נכלל!
statusbar.noScripts.notfound=אין קבצי script לדף!
statusbar.noScripts.scheme=ערכה אינה זמינה!
statusbar.updated=עודכן בהצלחה
+sync=
tooltip.loading=טוען...
Uninstall=הסר
untitledScript=קובץ Script ללא שם
View
5 extension/locale/hu/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=Általános
options.pane.ui=Felhasználói felület
options.requireBuiltInCerts=A biztonsági frissítésekhez beépített tanúsítványok szükségesek
options.requireSecured=A parancsfájlok frissítése a HTTPS protokollon keresztül történjen
+options.sync.desc=
+options.sync.ScriptishPrefs=
+options.sync.ScriptishPrefs.common=
+options.sync.ScriptishPrefs.editor=
options.title=Scriptish beállítások
options.toolbarbutton=Eszköztár gomb
options.toolbarbutton.showScripts=Aktív parancsfájlok számának megjelenése
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=Oldal kizárva!
statusbar.noScripts.notfound=Nincsenek parancsfájlok az oldalhoz!
statusbar.noScripts.scheme=Séma kikapcsolva!
statusbar.updated=frissítése sikeres
+sync=
tooltip.loading=Betöltés…
Uninstall=Eltávolítás
untitledScript=Névtelen parancsfájl
View
5 extension/locale/ja-JP/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=メイン
options.pane.ui=ユーザーインタフェース
options.requireBuiltInCerts=安全な更新に built-in 証明書を利用
options.requireSecured=HTTPS でユーザースクリプトを更新
+options.sync.desc=
+options.sync.ScriptishPrefs=
+options.sync.ScriptishPrefs.common=
+options.sync.ScriptishPrefs.editor=
options.title=Scriptish オプション
options.toolbarbutton=ツールバーのボタン
options.toolbarbutton.showScripts=アクティブなスクリプト数を表示
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=ページが除外(exclude)されました!
statusbar.noScripts.notfound=このページ用のスクリプトはありません!
statusbar.noScripts.scheme=スキーム(Scheme)が無効になっています!
statusbar.updated=は正常に更新されました
+sync=
tooltip.loading=読み込み中…
Uninstall=アンインストール
untitledScript=名称未定スクリプト
View
5 extension/locale/pl/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=Główne
options.pane.ui=Interfejs Użytkownika
options.requireBuiltInCerts=Aktualizacja bezpieczeństwa wymaga użycia wbudowanych certyfikatów
options.requireSecured=Wymagane skrypty użytkownika do aktualizacji przez HTTPS
+options.sync.desc=
+options.sync.ScriptishPrefs=
+options.sync.ScriptishPrefs.common=
+options.sync.ScriptishPrefs.editor=
options.title=Opcje Scriptish
options.toolbarbutton=Pasek narzędzi
options.toolbarbutton.showScripts=Pokaż liczbę aktywnych skryptów
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=Strona została wykluczona!
statusbar.noScripts.notfound=Brak skryptów dla strony!
statusbar.noScripts.scheme=Schemat został wyłączony!
statusbar.updated=poprawnie zaktualizowano
+sync=
tooltip.loading=Ładowanie...
Uninstall=Odinstalowanie
untitledScript=Skrypt bez nazwy
View
5 extension/locale/pt-BR/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=Principal
options.pane.ui=Interface
options.requireBuiltInCerts=Exigir que as atualizações seguras usem os certificados internos
options.requireSecured=Exigir que os scripts atualizem usando HTTPS
+options.sync.desc=
+options.sync.ScriptishPrefs=
+options.sync.ScriptishPrefs.common=
+options.sync.ScriptishPrefs.editor=
options.title=Opções do Scriptish
options.toolbarbutton=Botão da barra de ferramentas
options.toolbarbutton.showScripts=Exibir contador de scripts ativos
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=Scripts desabilitados nesta página!
statusbar.noScripts.notfound=Nenhum script para esta página!
statusbar.noScripts.scheme=Scripts desabilitados para este protocolo!
statusbar.updated=atualizado com sucesso
+sync=
tooltip.loading=Carregando...
Uninstall=Desinstalação
untitledScript=Script sem nome
View
5 extension/locale/ru-RU/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=Основные
options.pane.ui=Интерфейс
options.requireBuiltInCerts=Безопасное обновление требует использование встроенных сертификатов
options.requireSecured=Разрешить обновления скриптов только по протоколу HTTPS
+options.sync.desc=
+options.sync.ScriptishPrefs=
+options.sync.ScriptishPrefs.common=
+options.sync.ScriptishPrefs.editor=
options.title=Настройки Scriptish
options.toolbarbutton=Кнопка на тулбаре
options.toolbarbutton.showScripts=Показывать количество активных скриптов
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=
statusbar.noScripts.notfound=Нет скриптов для страницы!
statusbar.noScripts.scheme=
statusbar.updated=успешно обновлен(ы)
+sync=
tooltip.loading=Загрузка...
Uninstall=Удалить
untitledScript=Скрипт без имени
View
5 extension/locale/sv-SE/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=Allmänt
options.pane.ui=Användargränssnitt
options.requireBuiltInCerts=Säker uppdatering kräver användning av inbyggda certifikat
options.requireSecured=Kräv att användarskript uppdateras via HTTPS
+options.sync.desc=
+options.sync.ScriptishPrefs=
+options.sync.ScriptishPrefs.common=
+options.sync.ScriptishPrefs.editor=
options.title=Inställningar för Scriptish
options.toolbarbutton=Verktygsfältsknapp
options.toolbarbutton.showScripts=Visa antalet aktiva skript
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=Sidan är undantagen!
statusbar.noScripts.notfound=Inga skript för sidan!
statusbar.noScripts.scheme=Schemat är inaktiverat!
statusbar.updated=har uppdaterats
+sync=
tooltip.loading=Läser in…
Uninstall=Avinstallera
untitledScript=(Namnlöst skript)
View
5 extension/locale/zh-CN/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=常规
options.pane.ui=用户界面
options.requireBuiltInCerts=安全更新需要使用内置的证书
options.requireSecured=要求用户脚本使用 HTTPS 更新
+options.sync.desc=
+options.sync.ScriptishPrefs=
+options.sync.ScriptishPrefs.common=
+options.sync.ScriptishPrefs.editor=
options.title=Scriptish 选项
options.toolbarbutton=工具栏按钮
options.toolbarbutton.showScripts=显示活动的脚本数
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=页面已排除!
statusbar.noScripts.notfound=页面上没有脚本在运行!
statusbar.noScripts.scheme=Scheme 已禁用!
statusbar.updated=更新成功
+sync=
tooltip.loading=正在加载...
Uninstall=卸载
untitledScript=无标题的脚本
View
5 extension/locale/zh-TW/scriptish.properties
@@ -131,6 +131,10 @@ options.pane.main=主要
options.pane.ui=介面
options.requireBuiltInCerts=安全性更新必須使用內建的憑證
options.requireSecured=腳本必須使用 HTTPS 更新
+options.sync.desc=
+options.sync.ScriptishPrefs=
+options.sync.ScriptishPrefs.common=
+options.sync.ScriptishPrefs.editor=
options.title=Scriptish 選項
options.toolbarbutton=工具列按鈕
options.toolbarbutton.showScripts=顯示作用中的腳本數
@@ -153,6 +157,7 @@ statusbar.noScripts.excluded=頁面已排除!
statusbar.noScripts.notfound=沒有在此頁面執行的腳本!
statusbar.noScripts.scheme=協定已停用!
statusbar.updated=更新成功
+sync=
tooltip.loading=載入中…
Uninstall=移除
untitledScript=無標題的腳本
View
21 extension/modules/prefmanager.js
@@ -4,18 +4,20 @@ lazyUtil(this, "stringBundle");
const MIN_INT_32 = -0x80000000;
const MAX_INT_32 = 0x7FFFFFFF;
+const SYNC_PREFIX = "services.sync.prefs.sync.";
const Scriptish_prefRoot = new Scriptish_PrefManager();
/**
* Simple API on top of preferences for extensions.scriptish.
* Construct an instance by passing the startPoint of a preferences subtree.
* "extensions.scriptish." prefix is assumed.
*/
-function Scriptish_PrefManager(startPoint) {
+function Scriptish_PrefManager(startPoint, syncMode) {
if (!startPoint) startPoint = "";
startPoint = "extensions.scriptish." + startPoint;
- var pref = Services.prefs.getBranch(startPoint);
+ var pref =
+ Services.prefs.getBranch((syncMode ? SYNC_PREFIX : "") + startPoint);
var observers = {};
@@ -133,4 +135,19 @@ function Scriptish_PrefManager(startPoint) {
.removeObserver(prefName, observers[watcher]);
}
}
+
+ // Determine if the preference is currently set to be synchronized
+ this.isSynced = function(prefName) {
+ return this.getValue(prefName, false);
+ }
+
+ // Set a preference to be synchronized
+ this.sync = function(prefName) {
+ this.setValue(prefName, true);
+ }
+
+ // Stop a preference from being synchronized
+ this.unsync = function(prefName) {
+ this.setValue(prefName, false);
+ }
}
View
3 extension/skin/options.css
@@ -13,6 +13,9 @@ radio[pane="pane-ui"] {
radio[pane="pane-excludes"] {
-moz-image-region: rect(0px, 64px, 32px, 32px);
}
+radio[pane="pane-sync"] {
+ list-style-image: url(chrome://browser/skin/sync-32.png);
+}
radio[pane="pane-advanced"] {
-moz-image-region: rect(0px, 96px, 32px, 64px);
}

0 comments on commit 7052313

Please sign in to comment.