├── .gitignore ├── icon.png ├── .jpmignore ├── data ├── add.png ├── icon-16.png ├── icon-32.png ├── icon-36.png ├── icon-48.png ├── icon-64.png ├── remove.png ├── confirmation.html ├── configureFolders.html ├── confirmation.js └── configureFolders.js ├── run.sh ├── test.sh ├── .travis.yml ├── .eslintrc.json ├── lib ├── options.js ├── configure-folders.js ├── annotations.js ├── main.js ├── bookmark-sorter.js └── bookmarks.js ├── locale ├── zh-CN.properties ├── en-US.properties ├── fr.properties └── de.properties ├── genbookmarks.py ├── test ├── test-annotations.js ├── test-options.js ├── utils.js └── test-main.js ├── README.md ├── package.json └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.xpi 2 | *.swp 3 | *.iml 4 | .idea 5 | bookmarks*.html 6 | test-*.txt 7 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eric-bixby/auto-sort-bookmarks-pm/master/icon.png -------------------------------------------------------------------------------- /.jpmignore: -------------------------------------------------------------------------------- 1 | .* 2 | *.py 3 | *.sh 4 | *.xpi 5 | bookmarks*.html 6 | test-*.txt 7 | test/** 8 | -------------------------------------------------------------------------------- /data/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eric-bixby/auto-sort-bookmarks-pm/master/data/add.png -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | jpm xpi 3 | jpm -b /Applications/FirefoxDeveloperEdition.app run 4 | 5 | -------------------------------------------------------------------------------- /data/icon-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eric-bixby/auto-sort-bookmarks-pm/master/data/icon-16.png -------------------------------------------------------------------------------- /data/icon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eric-bixby/auto-sort-bookmarks-pm/master/data/icon-32.png -------------------------------------------------------------------------------- /data/icon-36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eric-bixby/auto-sort-bookmarks-pm/master/data/icon-36.png -------------------------------------------------------------------------------- /data/icon-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eric-bixby/auto-sort-bookmarks-pm/master/data/icon-48.png -------------------------------------------------------------------------------- /data/icon-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eric-bixby/auto-sort-bookmarks-pm/master/data/icon-64.png -------------------------------------------------------------------------------- /data/remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eric-bixby/auto-sort-bookmarks-pm/master/data/remove.png -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | timestamp=$( date +"%Y-%m-%d_%H-%M-%S" ) 4 | 5 | jpm -b /Applications/FirefoxDeveloperEdition.app test --tbpl > test-${timestamp}.txt 6 | 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # set language 2 | language: node_js 3 | 4 | # set version of node_js to build against 5 | node_js: 6 | - "4" 7 | 8 | # set version of Firefox to use for add-on testing 9 | addons: 10 | firefox: "47.0" 11 | 12 | # run Firefox in headless mode 13 | before_install: 14 | - "export DISPLAY=:99.0" 15 | - "sh -e /etc/init.d/xvfb start" 16 | 17 | # install JPM for building add-on 18 | before_script: 19 | - npm install jpm -g 20 | 21 | # run tests 22 | script: 23 | - npm run jpm-travis 24 | -------------------------------------------------------------------------------- /data/confirmation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 18 | 19 | 20 | 21 |

22 |

23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true, 4 | "browser": true, 5 | "es6": true 6 | }, 7 | "globals": { 8 | "XPCOMUtils": true 9 | }, 10 | "extends": "eslint:recommended", 11 | "rules": { 12 | "indent": [ 13 | "error", 14 | 4, 15 | { 16 | "SwitchCase": 1 17 | } 18 | ], 19 | "linebreak-style": [ 20 | "error", 21 | "unix" 22 | ], 23 | "quotes": [ 24 | "error", 25 | "double" 26 | ], 27 | "semi": [ 28 | "error", 29 | "always" 30 | ], 31 | "require-jsdoc": [ 32 | "error", 33 | { 34 | "require": { 35 | "FunctionDeclaration": true, 36 | "MethodDefinition": false, 37 | "ClassDeclaration": false, 38 | "ArrowFunctionExpression": false 39 | } 40 | } 41 | ] 42 | } 43 | } -------------------------------------------------------------------------------- /data/configureFolders.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 42 | 43 | 44 |

45 |

46 |

47 | 48 | 49 | -------------------------------------------------------------------------------- /data/confirmation.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | /** 21 | * Handle button click event. 22 | * @param event 23 | */ 24 | function buttonClicked(event) { 25 | self.port.emit("button-clicked", event.target.id); 26 | } 27 | 28 | let yesButton = document.querySelector("#button-yes"); 29 | let noButton = document.querySelector("#button-no"); 30 | let optionsButton = document.querySelector("#button-change-options"); 31 | 32 | yesButton.addEventListener("click", buttonClicked, false); 33 | noButton.addEventListener("click", buttonClicked, false); 34 | optionsButton.addEventListener("click", buttonClicked, false); 35 | 36 | self.port.on("show", function (iconURL) { 37 | let images = document.querySelectorAll("img"); 38 | if (images.length === 0) { 39 | let image = new Image(); 40 | image.alt = "Auto-Sort Bookmarks Icon"; 41 | image.src = iconURL; 42 | document.body.insertBefore(image, document.querySelector("#question")); 43 | } 44 | }); 45 | -------------------------------------------------------------------------------- /lib/options.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | const self = require("sdk/self"); 21 | const simplePrefs = require("sdk/simple-prefs"); 22 | const prefs = simplePrefs.prefs; 23 | 24 | /** 25 | * Get the option long name from the `shortName`. 26 | * @param {string} shortName The short name. 27 | * @return {string} The long name. 28 | */ 29 | function getOptionName(shortName) { 30 | return "extensions." + self.id + "." + shortName; 31 | } 32 | 33 | /** 34 | * Set the `maximum` of the `preference`. 35 | * @param {string} preference The preference name. 36 | * @param {Number} maximum The maximum. 37 | */ 38 | function setPreferenceMaximum(preference, maximum) { 39 | simplePrefs.on(preference, function () { 40 | if (prefs[preference] > maximum) { 41 | prefs[preference] = maximum; 42 | } 43 | }); 44 | } 45 | 46 | /** 47 | * Set the `minimum` of the `preference`. 48 | * @param {string} preference The preference name. 49 | * @param {Number} minimum The minimum. 50 | */ 51 | function setPreferenceMinimum(preference, minimum) { 52 | simplePrefs.on(preference, function () { 53 | if (prefs[preference] < minimum) { 54 | prefs[preference] = minimum; 55 | } 56 | }); 57 | } 58 | 59 | exports.getOptionName = getOptionName; 60 | exports.setPreferenceMaximum = setPreferenceMaximum; 61 | exports.setPreferenceMinimum = setPreferenceMinimum; 62 | -------------------------------------------------------------------------------- /locale/zh-CN.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Title 3 | # 4 | Auto-Sort Bookmarks=书签自动排序 5 | # 6 | # main.js (toolbar button) 7 | # 8 | sort_bookmarks=书签排序 9 | # 10 | # Preferences (same order as package.json) 11 | # 12 | auto_sort_title=自动排序 13 | delay_title=延时 14 | folder_delay_title=文件夹排序延时 15 | case_insensitive_title=区分大小写 16 | exclude_folders_title=待排序文件夹 17 | exclude_folders_label=设置... 18 | sort_by_title=排序依据 19 | sort_by_options.Name=名称 20 | sort_by_options.URL=URL 21 | sort_by_options.Description=描述 22 | sort_by_options.Keyword=关键词 23 | sort_by_options.Date Added=添加日期 24 | sort_by_options.Last Modified=最后修改日期 25 | sort_by_options.Last visited=最后访问日期 26 | sort_by_options.Visited count=访问次数 27 | sort_by_options.Reversed URL=URL倒序 28 | inverse_title=倒序 29 | then_sort_by_title=次级排序依据 30 | then_sort_by_options.None=无 31 | then_sort_by_options.Name=名称 32 | then_sort_by_options.URL=URL 33 | then_sort_by_options.Description=描述 34 | then_sort_by_options.Keyword=关键词 35 | then_sort_by_options.Date Added=添加日期 36 | then_sort_by_options.Last Modified=最后修改日期 37 | then_sort_by_options.Last visited=最后访问日期 38 | then_sort_by_options.Visited count=访问次数 39 | then_sort_by_options.Reversed URL=URL倒序 40 | then_inverse_title=次级排序依据倒序 41 | folder_sort_by_title=文件夹排序依据 42 | folder_sort_by_options.None=无 43 | folder_sort_by_options.Name=名称 44 | folder_sort_by_options.Description=描述 45 | folder_sort_by_options.Date Added=添加日期 46 | folder_sort_by_options.Last Modified=最后修改日期 47 | folder_inverse_title=文件夹排序倒序 48 | folder_sort_order_title=文件夹排序 49 | livemark_sort_order_title=活动书签排序 50 | smart_bookmark_sort_order_title=智能书签排序 51 | bookmark_sort_order_title=书签排序 52 | # 53 | # confirmation.html 54 | # 55 | Do you want to enable the autosort?=你希望启用自动排序吗? 56 | Yes=是 57 | No=否 58 | Change options=修改选项 59 | # 60 | # configureFolders.html 61 | # 62 | Folders to Sort=待排序文件夹 63 | Folders to Sort - Auto-Sort Bookmarks=待排序文件夹 - 书签自动排序 64 | Uncheck the folders to exclude when sorting.=排序时无视文件夹 65 | # 66 | # configure-folders.js 67 | # 68 | Recursive=递归 69 | The sub-folders are recursively excluded.=子文件夹递归排除 70 | Loading...=加载中... 71 | # 72 | # Folders 73 | # 74 | menu_title=书签菜单 75 | toolbar_title=书签工具栏 76 | unsorted_title=其它书签 77 | # 78 | # Folders 79 | # 80 | Bookmarks Menu=书签菜单 81 | Bookmarks Toolbar=书签工具栏 82 | Unsorted Bookmarks=其它书签 83 | -------------------------------------------------------------------------------- /locale/en-US.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Title 3 | # 4 | Auto-Sort Bookmarks=Auto-Sort Bookmarks 5 | # 6 | # main.js (toolbar button) 7 | # 8 | sort_bookmarks=Sort Bookmarks 9 | # 10 | # Preferences (same order as package.json) 11 | # 12 | auto_sort_title=Auto-sort 13 | delay_title=Delay 14 | folder_delay_title=Delay for Folders 15 | case_insensitive_title=Case Insensitive 16 | exclude_folders_title=Folders to Sort 17 | exclude_folders_label=Configure... 18 | sort_by_title=Sort By 19 | sort_by_options.Name=Name 20 | sort_by_options.URL=URL 21 | sort_by_options.Description=Description 22 | sort_by_options.Keyword=Keyword 23 | sort_by_options.Date Added=Date Added 24 | sort_by_options.Last Modified=Last Modified 25 | sort_by_options.Last visited=Last Visited 26 | sort_by_options.Visited count=Visited Count 27 | sort_by_options.Reversed URL=Reversed URL 28 | inverse_title=Inverse Order 29 | then_sort_by_title=Then Sort By 30 | then_sort_by_options.None=None 31 | then_sort_by_options.Name=Name 32 | then_sort_by_options.URL=URL 33 | then_sort_by_options.Description=Description 34 | then_sort_by_options.Keyword=Keyword 35 | then_sort_by_options.Date Added=Date Added 36 | then_sort_by_options.Last Modified=Last Modified 37 | then_sort_by_options.Last visited=Last Visited 38 | then_sort_by_options.Visited count=Visited Count 39 | then_sort_by_options.Reversed URL=Reversed URL 40 | then_inverse_title=Inverse Second Order 41 | folder_sort_by_title=Sort Folder By 42 | folder_sort_by_options.None=None 43 | folder_sort_by_options.Name=Name 44 | folder_sort_by_options.Description=Description 45 | folder_sort_by_options.Date Added=Date Added 46 | folder_sort_by_options.Last Modified=Last Modified 47 | folder_inverse_title=Inverse Folder Order 48 | folder_sort_order_title=Folder Sort Order 49 | livemark_sort_order_title=Livemark Sort Order 50 | smart_bookmark_sort_order_title=Smart Bookmark Sort Order 51 | bookmark_sort_order_title=Bookmark Sort Order 52 | # 53 | # confirmation.html 54 | # 55 | Do you want to enable the autosort?=Do you want to enable auto-sorting? 56 | Yes=Yes 57 | No=No 58 | Change options=Change options 59 | # 60 | # configureFolders.html 61 | # 62 | Folders to Sort=Folders to Sort 63 | Folders to Sort - Auto-Sort Bookmarks=Folders to Sort - Auto-Sort Bookmarks 64 | Uncheck the folders to exclude when sorting.=Uncheck the folders to exclude when sorting. 65 | # 66 | # configure-folders.js 67 | # 68 | Recursive=Recursive 69 | The sub-folders are recursively excluded.=The sub-folders are recursively excluded. 70 | Loading...=Loading... 71 | # 72 | # Folders 73 | # 74 | menu_title=Bookmarks Menu 75 | toolbar_title=Bookmarks Toolbar 76 | unsorted_title=Other Bookmarks 77 | # 78 | # Folders 79 | # 80 | Bookmarks Menu=Bookmarks Menu 81 | Bookmarks Toolbar=Bookmarks Toolbar 82 | Unsorted Bookmarks=Other Bookmarks 83 | -------------------------------------------------------------------------------- /genbookmarks.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | genbookmarks.py 5 | 6 | Haskell version: 7 | http://codereview.stackexchange.com/questions/101621/netscape-bookmark-file-generator 8 | Copyright (C) 2015 Boucher, Antoni 9 | 10 | Haskell version ported to Python by Eric Bixby. 11 | Copyright (C) 2016 Eric Bixby 12 | 13 | This program is free software: you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation, either version 3 of the License, or 16 | (at your option) any later version. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this program. If not, see . 25 | """ 26 | 27 | import sys 28 | import argparse 29 | import random 30 | import string 31 | 32 | def generateFileContent(outputFile, dirCount, linkCount): 33 | f = open(outputFile, "w") 34 | f.write("\n") 35 | f.write("\n") 36 | f.write("Bookmarks\n") 37 | f.write("

Bookmarks Menu

\n") 38 | f.write("\n") 39 | f.write("

\n") 40 | f.write(generateBookmarks(dirCount, linkCount)); 41 | f.write("

\n") 42 | f.close() 43 | 44 | def generateBookmarks(dirCount, linkCount): 45 | result = "" 46 | for d in range(0, dirCount): 47 | directoryName = generateName() 48 | result += "

" \ 49 | + directoryName \ 50 | + "

\n" \ 51 | + "

\n" 52 | for b in range(0, linkCount): 53 | bookmarkName = generateName() 54 | result += "

" \ 57 | + bookmarkName \ 58 | + "\n" 59 | result += "

\n" 60 | return result 61 | 62 | def generateName(): 63 | return ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(10)) 64 | 65 | def main(argv): 66 | parser = argparse.ArgumentParser() 67 | parser.add_argument("outputfile", help="output filename") 68 | parser.add_argument("--dircount", type=int, help="number of directories to generate", default=10) 69 | parser.add_argument("--linkcount", type=int, help="number of bookmarks to generate per directory", default=10) 70 | args = parser.parse_args() 71 | generateFileContent(args.outputfile, args.dircount, args.linkcount) 72 | 73 | if __name__ == "__main__": 74 | main(sys.argv[1:]) 75 | -------------------------------------------------------------------------------- /locale/fr.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Title 3 | # 4 | Auto-Sort Bookmarks=Auto-Sort Bookmarks 5 | # 6 | # main.js (toolbar button) 7 | # 8 | sort_bookmarks=Trier les marque-pages 9 | # 10 | # Preferences (same order as package.json) 11 | # 12 | auto_sort_title=Tri automatique 13 | delay_title=Délai 14 | folder_delay_title=Délai pour les dossiers 15 | case_insensitive_title=Insensible à la casse 16 | exclude_folders_title=Dossiers à trier 17 | exclude_folders_label=Configurer... 18 | sort_by_title=Trier par 19 | sort_by_options.Name=Nom 20 | sort_by_options.URL=URL 21 | sort_by_options.Description=Description 22 | sort_by_options.Keyword=Mot-clé 23 | sort_by_options.Date Added=Date d’ajout 24 | sort_by_options.Last Modified=Dernière modification 25 | sort_by_options.Last visited=Dernière visite 26 | sort_by_options.Visited count=Nombre de visites 27 | sort_by_options.Reversed URL=URL renversée 28 | inverse_title=Inverser l’ordre 29 | then_sort_by_title=Puis trier par 30 | then_sort_by_options.None=Aucun 31 | then_sort_by_options.Name=Nom 32 | then_sort_by_options.URL=URL 33 | then_sort_by_options.Description=Description 34 | then_sort_by_options.Keyword=Mot-clé 35 | then_sort_by_options.Date Added=Date d’ajout 36 | then_sort_by_options.Last Modified=Dernière modification 37 | then_sort_by_options.Last visited=Dernière visite 38 | then_sort_by_options.Visited count=Nombre de visites 39 | then_sort_by_options.Reversed URL=URL renversée 40 | then_inverse_title=Inverser le deuxième ordre 41 | folder_sort_by_title=Trier les dossiers par 42 | folder_sort_by_options.None=Aucun 43 | folder_sort_by_options.Name=Nom 44 | folder_sort_by_options.Description=Description 45 | folder_sort_by_options.Date Added=Date d’ajout 46 | folder_sort_by_options.Last Modified=Dernière modification 47 | folder_inverse_title=Inverser l’ordre des dossiers 48 | folder_sort_order_title=Ordre de tri des dossiers 49 | livemark_sort_order_title=Ordre de tri des marque-pages dynamiques 50 | smart_bookmark_sort_order_title=Ordre de tri des marque-pages intelligents 51 | bookmark_sort_order_title=Ordre de tri des marque-pages 52 | # 53 | # confirmation.html 54 | # 55 | Do you want to enable the autosort?=Voulez-vous activer le tri automatique ? 56 | Yes=Oui 57 | No=Non 58 | Change options=Préférences 59 | # 60 | # configureFolders.html 61 | # 62 | Folders to Sort=Dossiers à trier 63 | Folders to Sort - Auto-Sort Bookmarks=Dossiers à trier - Auto-Sort Bookmarks 64 | Uncheck the folders to exclude when sorting.=Décochez les dossiers à exclure lors du tri. 65 | # 66 | # configure-folders.js 67 | # 68 | Recursive=Récursif 69 | The sub-folders are recursively excluded.=Les sous-dossiers sont exclus récursivement. 70 | Loading...=Chargement... 71 | # 72 | # Folders 73 | # 74 | menu_title=Menu des marque-pages 75 | toolbar_title=Barre personnelle 76 | unsorted_title=Marque-pages non classés 77 | # 78 | # Folders 79 | # 80 | Bookmarks Menu=Menu des marque-pages 81 | Bookmarks Toolbar=Barre personnelle 82 | Unsorted Bookmarks=Marque-pages non classés 83 | -------------------------------------------------------------------------------- /locale/de.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Title 3 | # 4 | Auto-Sort Bookmarks=Auto-Sort Bookmarks 5 | # 6 | # main.js (toolbar button) 7 | # 8 | sort_bookmarks=Lesezeichen jetzt sortieren 9 | # 10 | # Preferences (same order as package.json) 11 | # 12 | auto_sort_title=Automatisch sortieren 13 | delay_title=Verzögerung 14 | folder_delay_title=Verzögerung für Ordner 15 | case_insensitive_title=Case Insensitive 16 | exclude_folders_title=Ordner zu Sortieren 17 | exclude_folders_label=Konfigurieren... 18 | sort_by_title=Zuerst sortieren nach 19 | sort_by_options.Name=Name 20 | sort_by_options.URL=URL 21 | sort_by_options.Description=Beschreibung 22 | sort_by_options.Date Added=Hinzugefügt 23 | sort_by_options.Keyword=Schlüsselwort 24 | sort_by_options.Last Modified=Zuletzt geändert 25 | sort_by_options.Last visited=Zuletzt besucht 26 | sort_by_options.Visited count=Meistbesucht 27 | sort_by_options.Reversed URL=Umgekehrt URL 28 | inverse_title=Reihenfolge umkehren 29 | then_sort_by_title=Anschließend sortieren nach 30 | then_sort_by_options.None=Keine Festlegung 31 | then_sort_by_options.Name=Name 32 | then_sort_by_options.URL=URL 33 | then_sort_by_options.Description=Beschreibung 34 | then_sort_by_options.Date Added=Hinzugefügt 35 | then_sort_by_options.Keyword=Schlüsselwort 36 | then_sort_by_options.Last Modified=Zuletzt geändert 37 | then_sort_by_options.Last visited=Zuletzt besucht 38 | then_sort_by_options.Visited count=Meistbesucht 39 | then_sort_by_options.Reversed URL=Umgekehrt URL 40 | then_inverse_title=Zweitkriterium=Reihenfolge umkehren 41 | folder_sort_by_title=Sortieren Ordner 42 | folder_sort_by_options.None=Keiner 43 | folder_sort_by_options.Name=Name 44 | folder_sort_by_options.Description=Beschreibung 45 | folder_sort_by_options.Date Added=Hinzugefügt 46 | folder_sort_by_options.Last Modified=Zuletzt geändert 47 | folder_inverse_title=Inverse Ordner bestellen 48 | folder_sort_order_title=Ordner 49 | livemark_sort_order_title=Dynamische Lesezeichen 50 | smart_bookmark_sort_order_title=Intelligente Lesezeichen 51 | bookmark_sort_order_title=Lesezeichen 52 | # 53 | # confirmation.html 54 | # 55 | Do you want to enable the autosort?=Möchten Sie das automatische Sortieren aktivieren? 56 | No=Nein 57 | Yes=Ja 58 | Change options=Einstellungen ändern 59 | # 60 | # configureFolders.html 61 | # 62 | Folders to Sort=Ordner zu Sortieren 63 | Folders to Sort - Auto-Sort Bookmarks=Ordner zu Sortieren - Auto-Sort Bookmarks 64 | Uncheck the folders to exclude when sorting.=Deaktivieren Sie die Ordner ausschließen, beim sortieren. 65 | # 66 | # configure-folders.js 67 | # 68 | Recursive=Rekursive 69 | The sub-folders are recursively excluded.=Die Unterordner werden rekursiv ausgeschlossen. 70 | Loading...=Laden... 71 | # 72 | # Folders 73 | # 74 | menu_title=Lesezeichen-Menü 75 | toolbar_title=Lesezeichen-Symbolleiste 76 | unsorted_title=Unsortierte Lesezeichen 77 | # 78 | # Folders 79 | # 80 | Bookmarks Menu=Lesezeichen-Menü 81 | Bookmarks Toolbar=Lesezeichen-Symbolleiste 82 | Unsorted Bookmarks=Unsortierte Lesezeichen 83 | -------------------------------------------------------------------------------- /test/test-annotations.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | const {getDescription, isLivemark, isSmartBookmark} = require("lib/annotations"); 21 | const {Bookmark, menuFolder} = require("lib/bookmarks"); 22 | const {createBookmark, createFolder, createLivemark, createSeparator, createSmartBookmark, setDescription} = require("./utils"); 23 | 24 | exports.testDescription = function (assert) { 25 | assert.strictEqual(getDescription(undefined), ""); 26 | 27 | let item = createBookmark("Test title", "http://test.url/", menuFolder); 28 | assert.strictEqual(getDescription(item), ""); 29 | 30 | setDescription(item, "Test description"); 31 | assert.strictEqual(getDescription(item), "Test description"); 32 | 33 | setDescription(item, "New description"); 34 | assert.strictEqual(getDescription(item), "New description"); 35 | }; 36 | 37 | exports.testLivemark = function (assert) { 38 | let item = createBookmark("Test title", "http://test.url/", menuFolder); 39 | assert.strictEqual(isLivemark(item.id), false); 40 | 41 | item = createLivemark("Stack Overflow", "http://stackoverflow.com/feeds", menuFolder); 42 | assert.strictEqual(isLivemark(item.id), true); 43 | 44 | item = createFolder("Test Folder", menuFolder); 45 | assert.strictEqual(isLivemark(item.id), false); 46 | 47 | item = createSmartBookmark("Test Smart Bookmark", "MostVisited", "place:sort=8&maxResults=10", menuFolder); 48 | assert.strictEqual(isLivemark(item.id), false); 49 | 50 | item = createSeparator(menuFolder); 51 | assert.strictEqual(isLivemark(item.id), false); 52 | }; 53 | 54 | exports.testSmartBookmark = function (assert) { 55 | let item = createBookmark("Test title", "http://test.url/", menuFolder); 56 | assert.strictEqual(isSmartBookmark(item.id), false); 57 | 58 | item = createLivemark("Stack Overflow", "http://stackoverflow.com/feeds", menuFolder); 59 | assert.strictEqual(isSmartBookmark(item.id), false); 60 | 61 | item = createFolder("Test Folder", menuFolder); 62 | assert.strictEqual(isSmartBookmark(item.id), false); 63 | 64 | item = createSmartBookmark("Test Smart Bookmark", "MostVisited", "place:sort=8&maxResults=10", menuFolder); 65 | assert.strictEqual(isSmartBookmark(item.id), true); 66 | 67 | item = createSeparator(menuFolder); 68 | assert.strictEqual(isSmartBookmark(item.id), false); 69 | }; 70 | 71 | require("sdk/test").run(exports); 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [Auto-Sort Bookmarks](https://addons.mozilla.org/en-US/firefox/addon/auto-sort-bookmarks/) 2 | ========================================================================================== 3 | 4 | Pale Moon or Firefox (before version 57/Quantum) Plugin to Sort Bookmarks by Multiple Criteria. 5 | 6 | **Please backup your current bookmarks in case you do not like the new bookmarks order. Thus, you could restore them.** 7 | 8 | This extension provides a few options categorized within these categories: 9 | * Main Options 10 | * Exclude Folders 11 | * Sort Criteria 12 | * Sort Order 13 | 14 | These options work like this: 15 | 16 | **Main Options:** 17 | 18 | * **Auto-sort:** if this option is enabled, the bookmarks will be sorted when Firefox is opened, when this option is activated and when bookmarks are added, changed, moved or deleted. 19 | This means you cannot move any bookmarks in the same folder, unless it is moved over a separator. 20 | * **Delay:** allow to define a delay (in seconds) before automatically sorting bookmarks. 21 | * **Delay for Folders:** allow to define a delay (in seconds) before automatically sorting folders. This is to avoid that a new folder is sorted before you can choose it when adding a new bookmark. 22 | * **Case Insensitive:** if activated, the bookmarks will be sorted without considering the letter case. 23 | 24 | **Exclude Folders:** 25 | 26 | This button opens a new tab allowing you to exclude folders when sorting. If you uncheck the checkbox next to a folder, it wont be sorted, but the children folders will be sorted. 27 | If you want to exclude a folder recursively from being sorted, check the recursive checkbox. 28 | 29 | **Sort Criteria:** 30 | 31 | * **Sort By:** allow to specify the first sort criteria, that is to say, the order that will be used to sort the bookmarks. The choices are : name, url, description, keyword, date added, last modified, last visited, visited count and reversed base-URL. 32 | * **Inverse Order:** if this option is enabled, the order specified in "Sort By" will be reversed. So the order will be descending. 33 | * **Then Sort By:** allow to specify a second sort criteria (optional). For instance, if the first sort criteria is the name, it is possible to choose a second sort criteria to sort bookmarks with the same name. 34 | * **Inverse Second Order:** if this option is enabled, the order specified in "Then Sort By" will be reversed. 35 | * **Sort Folder By:** allow to specify a different sort criteria for folders. For instance, you might want to sort folders by name and other kinds of bookmarks by last visited. 36 | * **Inverse Folder Order:** if this option is enabled, the order speficied in "Sort Folder By" will be reversed. 37 | 38 | **Sort Order:** 39 | 40 | * **Folder Sort Order:** this option specify the order in which the folders are sorted. For instance, it is possible to sort folders before livemarks, smart bookmarks and bookmarks. To do this, the folder sort order should be lesser than the other sort orders. 41 | If the sort order of two types are at the same level, the bookmarks from these types will be sorted together. 42 | * **Livemark Sort Order:** this option specify the sort order of livemarks. 43 | * **Smart Bookmark Sort Order:** this option specify the sort order of smart bookmarks 44 | * **Bookmark Sort Order:** this option specify the bookmark sort order. 45 | -------------------------------------------------------------------------------- /lib/configure-folders.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | const _ = require("sdk/l10n").get; 21 | const self = require("sdk/self"); 22 | const data = self.data; 23 | const tabs = require("sdk/tabs"); 24 | const {removeDoNotSortAnnotation, removeRecursiveAnnotation, setDoNotSortAnnotation, setRecursiveAnnotation} = require("lib/annotations"); 25 | const {BookmarkManager, Folder, getChildrenFolders, getRootFolders} = require("lib/bookmarks"); 26 | const bookmarkManager = new BookmarkManager({}); 27 | 28 | /** 29 | * Show the page to configure the folders to exclude. 30 | */ 31 | function showConfigureFoldersToExclude() { 32 | return function () { 33 | /** 34 | * Send children. 35 | * @param worker 36 | * @returns {Function} 37 | */ 38 | function sendChildren(worker) { 39 | return function (parentID) { 40 | let children = getChildrenFolders(parentID); 41 | worker.port.emit("children", parentID, children); 42 | }; 43 | } 44 | 45 | let worker; 46 | 47 | /** 48 | * Handle onRemove event. 49 | * @param item 50 | */ 51 | function onRemove(item) { 52 | if (worker && item instanceof Folder) { 53 | worker.port.emit("remove-folder", item.id); 54 | } 55 | } 56 | 57 | bookmarkManager.on("remove", onRemove); 58 | 59 | tabs.open({ 60 | url: data.url("configureFolders.html"), 61 | onOpen: function (tab) { 62 | tab.on("ready", function () { 63 | worker = tab.attach({ 64 | contentScriptFile: data.url("configureFolders.js") 65 | }); 66 | 67 | worker.port.on("sort-checkbox-change", function (folderID, activated) { 68 | if (activated) { 69 | removeDoNotSortAnnotation(folderID); 70 | } 71 | else { 72 | setDoNotSortAnnotation(folderID); 73 | } 74 | }); 75 | 76 | worker.port.on("recursive-checkbox-change", function (folderID, activated) { 77 | if (activated) { 78 | setRecursiveAnnotation(folderID); 79 | } 80 | else { 81 | removeRecursiveAnnotation(folderID); 82 | } 83 | }); 84 | 85 | worker.port.on("query-children", sendChildren(worker)); 86 | 87 | const texts = { 88 | recursiveText: _("Recursive"), 89 | messageText: _("The sub-folders are recursively excluded."), 90 | loadingText: _("Loading..."), 91 | }; 92 | 93 | worker.port.emit("init", getRootFolders(), data.url("add.png"), data.url("remove.png"), texts); 94 | }); 95 | }, 96 | 97 | onClose: function () { 98 | worker = null; 99 | bookmarkManager.removeListener("remove", onRemove); 100 | }, 101 | }); 102 | }; 103 | } 104 | 105 | exports.showConfigureFoldersToExclude = showConfigureFoldersToExclude; 106 | -------------------------------------------------------------------------------- /test/test-options.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | const {get, has, reset, set} = require("sdk/preferences/service"); 21 | const self = require("sdk/self"); 22 | const simplePrefs = require("sdk/simple-prefs"); 23 | const prefs = simplePrefs.prefs; 24 | const {setPreferenceMaximum, setPreferenceMinimum} = require("lib/options"); 25 | const {getOptionName} = require("./utils"); 26 | 27 | /** 28 | * Set the value of the `name`d preference. 29 | * @param {string} name The preference name. 30 | * @return {boolean|string|int} The preference value. 31 | */ 32 | function getOption(name) { 33 | return get(getOptionName(name)); 34 | } 35 | 36 | /** 37 | * Set the `value` of the `name`d preference. 38 | * @param {string} name The preference name. 39 | * @param {boolean|string|int} value The preference value. 40 | */ 41 | function setOption(name, value) { 42 | set(getOptionName(name), value); 43 | } 44 | 45 | /** 46 | * Test the setPreferenceMaximum() function. 47 | */ 48 | exports.testPreferenceMaximum = function (assert) { 49 | setPreferenceMaximum("testMax", 15); 50 | 51 | setOption("testMax", 5); 52 | assert.strictEqual(getOption("testMax"), 5); 53 | 54 | setOption("testMax", 15); 55 | assert.strictEqual(getOption("testMax"), 15); 56 | 57 | setOption("testMax", 10); 58 | assert.strictEqual(getOption("testMax"), 10); 59 | 60 | setOption("testMax", 20); 61 | assert.strictEqual(getOption("testMax"), 15); 62 | 63 | setOption("testMax", 0); 64 | assert.strictEqual(getOption("testMax"), 0); 65 | 66 | setOption("testMax", 16); 67 | assert.strictEqual(getOption("testMax"), 15); 68 | 69 | setOption("testMax", -30); 70 | assert.strictEqual(getOption("testMax"), -30); 71 | 72 | setOption("testMax", 17); 73 | assert.strictEqual(getOption("testMax"), 15); 74 | 75 | reset(getOptionName("testMax")); 76 | }; 77 | 78 | /** 79 | * Test the setPreferenceMaximum() and setPreferenceMinimum() functions on the same option. 80 | */ 81 | exports.testPreferenceMaximumMinimum = function (assert) { 82 | setPreferenceMaximum("testMaxMin", 15); 83 | setPreferenceMinimum("testMaxMin", 2); 84 | 85 | setOption("testMaxMin", 5); 86 | assert.strictEqual(getOption("testMaxMin"), 5); 87 | 88 | setOption("testMaxMin", 15); 89 | assert.strictEqual(getOption("testMaxMin"), 15); 90 | 91 | setOption("testMaxMin", 10); 92 | assert.strictEqual(getOption("testMaxMin"), 10); 93 | 94 | setOption("testMaxMin", 20); 95 | assert.strictEqual(getOption("testMaxMin"), 15); 96 | 97 | setOption("testMaxMin", 0); 98 | assert.strictEqual(getOption("testMaxMin"), 2); 99 | 100 | setOption("testMaxMin", 16); 101 | assert.strictEqual(getOption("testMaxMin"), 15); 102 | 103 | setOption("testMaxMin", -30); 104 | assert.strictEqual(getOption("testMaxMin"), 2); 105 | 106 | setOption("testMaxMin", 17); 107 | assert.strictEqual(getOption("testMaxMin"), 15); 108 | 109 | setOption("testMaxMin", 2); 110 | assert.strictEqual(getOption("testMaxMin"), 2); 111 | 112 | setOption("testMaxMin", 22); 113 | assert.strictEqual(getOption("testMaxMin"), 15); 114 | 115 | setOption("testMaxMin", 1); 116 | assert.strictEqual(getOption("testMaxMin"), 2); 117 | 118 | setOption("testMaxMin", 30); 119 | assert.strictEqual(getOption("testMaxMin"), 15); 120 | 121 | setOption("testMaxMin", -2); 122 | assert.strictEqual(getOption("testMaxMin"), 2); 123 | 124 | setOption("testMaxMin", -1); 125 | assert.strictEqual(getOption("testMaxMin"), 2); 126 | 127 | reset(getOptionName("testMaxMin")); 128 | }; 129 | 130 | /** 131 | * Test the setPreferenceMinimum() function. 132 | */ 133 | exports.testPreferenceMinimum = function (assert) { 134 | setPreferenceMinimum("testMin", 2); 135 | 136 | setOption("testMin", 5); 137 | assert.strictEqual(getOption("testMin"), 5); 138 | 139 | setOption("testMin", 2); 140 | assert.strictEqual(getOption("testMin"), 2); 141 | 142 | setOption("testMin", 10); 143 | assert.strictEqual(getOption("testMin"), 10); 144 | 145 | setOption("testMin", 0); 146 | assert.strictEqual(getOption("testMin"), 2); 147 | 148 | setOption("testMin", 22); 149 | assert.strictEqual(getOption("testMin"), 22); 150 | 151 | setOption("testMin", 1); 152 | assert.strictEqual(getOption("testMin"), 2); 153 | 154 | setOption("testMin", 30); 155 | assert.strictEqual(getOption("testMin"), 30); 156 | 157 | setOption("testMin", -2); 158 | assert.strictEqual(getOption("testMin"), 2); 159 | 160 | reset(getOptionName("testMin")); 161 | }; 162 | 163 | require("sdk/test").run(exports); 164 | -------------------------------------------------------------------------------- /lib/annotations.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | const {Cc, Ci} = require("chrome"); 21 | const annotationService = Cc["@mozilla.org/browser/annotation-service;1"].getService(Ci.nsIAnnotationService); 22 | const descriptionAnnotation = "bookmarkProperties/description"; 23 | const livemarkAnnotation = "livemark/siteURI"; 24 | const smartBookmarkAnnotation = "Places/SmartBookmark"; 25 | 26 | /** 27 | * Get the item description. 28 | * @param {*} item The item. 29 | * @return {*} The item description. 30 | */ 31 | function getDescription(item) { 32 | let description; 33 | try { 34 | description = annotationService.getItemAnnotation(item.id, descriptionAnnotation); 35 | } 36 | catch (exception) { 37 | description = ""; 38 | } 39 | 40 | return description; 41 | } 42 | 43 | /** 44 | * Get an item annotation. 45 | * @param itemID The item ID. 46 | * @param name The item name. 47 | * @returns {*} The item annotation. 48 | */ 49 | function getItemAnnotation(itemID, name) { 50 | let annotation; 51 | try { 52 | annotation = annotationService.getItemAnnotation(itemID, name); 53 | } 54 | catch (exception) { 55 | // Do nothing. 56 | } 57 | 58 | return annotation; 59 | } 60 | 61 | /** 62 | * Check if an item has a do not sort annotation. 63 | * @param itemID 64 | * @return {boolean} 65 | */ 66 | function hasDoNotSortAnnotation(itemID) { 67 | let annotation = getItemAnnotation(itemID, "autosortbookmarks/donotsort"); 68 | return annotation !== undefined; 69 | } 70 | 71 | /** 72 | * Check if an item has a recursive annotation. 73 | * @param itemID 74 | * @return {boolean} 75 | */ 76 | function hasRecursiveAnnotation(itemID) { 77 | let annotation = getItemAnnotation(itemID, "autosortbookmarks/recursive"); 78 | return annotation !== undefined; 79 | } 80 | 81 | /** 82 | * Check if an item is recursively excluded. 83 | * @param itemID 84 | * @return {boolean} 85 | */ 86 | function isRecursivelyExcluded(itemID) { 87 | return hasDoNotSortAnnotation(itemID) && hasRecursiveAnnotation(itemID); 88 | } 89 | 90 | /** 91 | * Check whether `itemID` is a livemark. 92 | * @param {int} itemID The item ID. 93 | * @return {*} Whether the item is a livemark or not. 94 | */ 95 | function isLivemark(itemID) { 96 | return annotationService.itemHasAnnotation(itemID, livemarkAnnotation); 97 | } 98 | 99 | /** 100 | * Check whether `itemID` is a smart bookmark. 101 | * @param {int} itemID The item ID. 102 | * @return {boolean} Whether the item is a smart bookmark or not. 103 | */ 104 | function isSmartBookmark(itemID) { 105 | return annotationService.itemHasAnnotation(itemID, smartBookmarkAnnotation); 106 | } 107 | 108 | /** 109 | * Remove an item annotation. 110 | * @param itemID 111 | * @param name 112 | */ 113 | function removeItemAnnotation(itemID, name) { 114 | annotationService.removeItemAnnotation(itemID, name); 115 | } 116 | 117 | /** 118 | * Remove the do not sort annotation on an item. 119 | * @param itemID 120 | */ 121 | function removeDoNotSortAnnotation(itemID) { 122 | removeItemAnnotation(itemID, "autosortbookmarks/donotsort"); 123 | } 124 | 125 | /** 126 | * Remove the recursive annotation on an item. 127 | * @param itemID 128 | */ 129 | function removeRecursiveAnnotation(itemID) { 130 | removeItemAnnotation(itemID, "autosortbookmarks/recursive"); 131 | } 132 | 133 | /** 134 | * Set an item annotation. 135 | * @param itemID 136 | * @param name 137 | * @param value 138 | */ 139 | function setItemAnnotation(itemID, name, value) { 140 | const {Bookmark} = require("lib/bookmarks"); 141 | if (Bookmark.exists(itemID)) { 142 | annotationService.setItemAnnotation(itemID, name, value, 0, annotationService.EXPIRE_NEVER); 143 | } 144 | } 145 | 146 | /** 147 | * Set the do not sort annotation on an item. 148 | * @param itemID 149 | */ 150 | function setDoNotSortAnnotation(itemID) { 151 | setItemAnnotation(itemID, "autosortbookmarks/donotsort", true); 152 | } 153 | 154 | /** 155 | * Set the recursive annotation on an item. 156 | * @param itemID 157 | */ 158 | function setRecursiveAnnotation(itemID) { 159 | setItemAnnotation(itemID, "autosortbookmarks/recursive", true); 160 | } 161 | 162 | exports.getDescription = getDescription; 163 | exports.getItemAnnotation = getItemAnnotation; 164 | exports.hasDoNotSortAnnotation = hasDoNotSortAnnotation; 165 | exports.hasRecursiveAnnotation = hasRecursiveAnnotation; 166 | exports.isRecursivelyExcluded = isRecursivelyExcluded; 167 | exports.isLivemark = isLivemark; 168 | exports.isSmartBookmark = isSmartBookmark; 169 | exports.removeItemAnnotation = removeItemAnnotation; 170 | exports.removeDoNotSortAnnotation = removeDoNotSortAnnotation; 171 | exports.removeRecursiveAnnotation = removeRecursiveAnnotation; 172 | exports.setItemAnnotation = setItemAnnotation; 173 | exports.setDoNotSortAnnotation = setDoNotSortAnnotation; 174 | exports.setRecursiveAnnotation = setRecursiveAnnotation; 175 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auto_sort_bookmarks", 3 | "description": "Sort bookmarks by multiple criteria", 4 | "version": "2.10.12", 5 | "author": "Antoni Boucher", 6 | "bugs": { 7 | "url": "https://github.com/eric-bixby/auto-sort-bookmarks-pm/issues" 8 | }, 9 | "engines": { 10 | "firefox": ">=38.0a1", 11 | "{8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4}": ">=27.1.0b1" 12 | }, 13 | "homepage": "https://github.com/eric-bixby/auto-sort-bookmarks-pm", 14 | "icon": "data/icon-48.png", 15 | "icon64": "data/icon-64.png", 16 | "id": "sortbookmarks@bouanto", 17 | "keywords": [ 18 | "bookmarks", 19 | "sorter" 20 | ], 21 | "license": "GPL-3.0", 22 | "main": "lib/main.js", 23 | "permissions": { 24 | "multiprocess": true 25 | }, 26 | "preferences": [ 27 | { 28 | "name": "auto_sort", 29 | "title": "Auto-sort", 30 | "type": "bool", 31 | "value": false 32 | }, 33 | { 34 | "name": "delay", 35 | "title": "Delay", 36 | "type": "integer", 37 | "value": 0 38 | }, 39 | { 40 | "name": "folder_delay", 41 | "title": "Delay for Folders", 42 | "type": "integer", 43 | "value": 30 44 | }, 45 | { 46 | "name": "case_insensitive", 47 | "title": "Case Insensitive", 48 | "type": "bool", 49 | "value": false 50 | }, 51 | { 52 | "label": "Configure...", 53 | "name": "exclude_folders", 54 | "title": "Folders to Sort", 55 | "type": "control" 56 | }, 57 | { 58 | "name": "sort_by", 59 | "title": "Sort By", 60 | "type": "menulist", 61 | "value": 0, 62 | "options": [ 63 | { 64 | "value": "0", 65 | "label": "Name" 66 | }, 67 | { 68 | "value": "1", 69 | "label": "URL" 70 | }, 71 | { 72 | "value": "2", 73 | "label": "Description" 74 | }, 75 | { 76 | "value": "3", 77 | "label": "Keyword" 78 | }, 79 | { 80 | "value": "4", 81 | "label": "Date Added" 82 | }, 83 | { 84 | "value": "5", 85 | "label": "Last Modified" 86 | }, 87 | { 88 | "value": "6", 89 | "label": "Last visited" 90 | }, 91 | { 92 | "value": "7", 93 | "label": "Visited count" 94 | }, 95 | { 96 | "value": "8", 97 | "label": "Reversed URL" 98 | } 99 | ] 100 | }, 101 | { 102 | "name": "inverse", 103 | "title": "Inverse Order", 104 | "type": "bool", 105 | "value": false 106 | }, 107 | { 108 | "name": "then_sort_by", 109 | "title": "Then Sort By", 110 | "type": "menulist", 111 | "value": -1, 112 | "options": [ 113 | { 114 | "value": "-1", 115 | "label": "None" 116 | }, 117 | { 118 | "value": "0", 119 | "label": "Name" 120 | }, 121 | { 122 | "value": "1", 123 | "label": "URL" 124 | }, 125 | { 126 | "value": "2", 127 | "label": "Description" 128 | }, 129 | { 130 | "value": "3", 131 | "label": "Keyword" 132 | }, 133 | { 134 | "value": "4", 135 | "label": "Date Added" 136 | }, 137 | { 138 | "value": "5", 139 | "label": "Last Modified" 140 | }, 141 | { 142 | "value": "6", 143 | "label": "Last visited" 144 | }, 145 | { 146 | "value": "7", 147 | "label": "Visited count" 148 | }, 149 | { 150 | "value": "8", 151 | "label": "Reversed URL" 152 | } 153 | ] 154 | }, 155 | { 156 | "name": "then_inverse", 157 | "title": "Inverse Second Order", 158 | "type": "bool", 159 | "value": false 160 | }, 161 | { 162 | "name": "folder_sort_by", 163 | "title": "Sort Folder By", 164 | "type": "menulist", 165 | "value": 0, 166 | "options": [ 167 | { 168 | "value": "-1", 169 | "label": "None" 170 | }, 171 | { 172 | "value": "0", 173 | "label": "Name" 174 | }, 175 | { 176 | "value": "2", 177 | "label": "Description" 178 | }, 179 | { 180 | "value": "4", 181 | "label": "Date Added" 182 | }, 183 | { 184 | "value": "5", 185 | "label": "Last Modified" 186 | } 187 | ] 188 | }, 189 | { 190 | "name": "folder_inverse", 191 | "title": "Inverse Folder Order", 192 | "type": "bool", 193 | "value": false 194 | }, 195 | { 196 | "name": "folder_sort_order", 197 | "title": "Folder Sort Order", 198 | "type": "integer", 199 | "value": 1 200 | }, 201 | { 202 | "name": "livemark_sort_order", 203 | "title": "Livemark Sort Order", 204 | "type": "integer", 205 | "value": 2 206 | }, 207 | { 208 | "name": "smart_bookmark_sort_order", 209 | "title": "Smart Bookmark Sort Order", 210 | "type": "integer", 211 | "value": 3 212 | }, 213 | { 214 | "name": "bookmark_sort_order", 215 | "title": "Bookmark Sort Order", 216 | "type": "integer", 217 | "value": 4 218 | } 219 | ], 220 | "repository": { 221 | "type": "git", 222 | "url": "git+https://github.com/eric-bixby/auto-sort-bookmarks-pm.git" 223 | }, 224 | "scripts": { 225 | "jpm-travis": "jpm --binary `which firefox` test -v" 226 | }, 227 | "title": "Auto-Sort Bookmarks" 228 | } 229 | -------------------------------------------------------------------------------- /data/configureFolders.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | let addIcon; 21 | let loadingText = ""; 22 | let messageText = ""; 23 | let recursiveText = ""; 24 | let removeIcon; 25 | let fetching = new Set(); 26 | 27 | /** 28 | * Send value. 29 | * @param type 30 | * @param folderID 31 | * @param checkbox 32 | * @param image 33 | * @returns {Function} 34 | */ 35 | function sendValue(type, folderID, checkbox, image) { 36 | return function () { 37 | if (type === "recursive" && image.getAttribute("data-state") === "remove") { 38 | let children = document.querySelector("#folder-" + folderID); 39 | children.style.display = "block"; 40 | } 41 | self.port.emit(type + "-checkbox-change", folderID, checkbox.checked); 42 | }; 43 | } 44 | 45 | /** 46 | * Toggle children. 47 | * @param parentID 48 | * @param image 49 | * @param children 50 | * @param recursiveCheckbox 51 | * @returns {Function} 52 | */ 53 | function toggleChildren(parentID, image, children, recursiveCheckbox) { 54 | return function () { 55 | if (!fetching.has(parentID)) { 56 | if (image.getAttribute("data-state") === "add") { 57 | image.src = removeIcon; 58 | image.setAttribute("data-state", "remove"); 59 | 60 | if (!recursiveCheckbox.checked) { 61 | children.style.display = "block"; 62 | children.textContent = loadingText; 63 | } 64 | 65 | fetching.add(parentID); 66 | setTimeout(function () { 67 | self.port.emit("query-children", parentID); 68 | }, 100); 69 | } 70 | else { 71 | image.src = addIcon; 72 | image.setAttribute("data-state", "add"); 73 | 74 | if (children) { 75 | children.style.display = "none"; 76 | } 77 | } 78 | } 79 | }; 80 | } 81 | 82 | /** 83 | * Append folder. 84 | * @param folder 85 | * @param list 86 | */ 87 | function appendFolder(folder, list) { 88 | let listItem = document.createElement("li"); 89 | 90 | let recursiveCheckbox = document.createElement("input"); 91 | let recursiveLabel = document.createElement("label"); 92 | 93 | let children = document.createElement("ul"); 94 | children.id = "folder-" + folder.id; 95 | 96 | let icon = document.createElement("img"); 97 | icon.alt = "plus-minus"; 98 | icon.src = addIcon; 99 | icon.setAttribute("data-state", "add"); 100 | icon.addEventListener("click", toggleChildren(folder.id, icon, children, recursiveCheckbox), false); 101 | listItem.appendChild(icon); 102 | 103 | let label = document.createElement("label"); 104 | label.textContent = folder.title; 105 | label.addEventListener("click", toggleChildren(folder.id, icon, children, recursiveCheckbox), false); 106 | listItem.appendChild(label); 107 | 108 | let checkbox = document.createElement("input"); 109 | checkbox.type = "checkbox"; 110 | checkbox.checked = !folder.excluded; 111 | checkbox.addEventListener("change", sendValue("sort", folder.id, checkbox), false); 112 | checkbox.addEventListener("change", function () { 113 | recursiveCheckbox.disabled = checkbox.checked; 114 | recursiveLabel.disabled = checkbox.checked; 115 | }, false); 116 | 117 | listItem.appendChild(checkbox); 118 | 119 | recursiveLabel.textContent = recursiveText; 120 | recursiveLabel.htmlFor = "recursive-" + folder.id; 121 | recursiveLabel.className = "recursive"; 122 | recursiveLabel.disabled = checkbox.checked; 123 | listItem.appendChild(recursiveLabel); 124 | 125 | let message = document.createElement("p"); 126 | 127 | recursiveCheckbox.type = "checkbox"; 128 | recursiveCheckbox.id = "recursive-" + folder.id; 129 | recursiveCheckbox.checked = folder.recursivelyExcluded; 130 | recursiveCheckbox.disabled = checkbox.checked; 131 | recursiveCheckbox.className = "recursive-checkbox"; 132 | recursiveCheckbox.addEventListener("change", sendValue("recursive", folder.id, recursiveCheckbox, icon), false); 133 | listItem.appendChild(recursiveCheckbox); 134 | 135 | message.textContent = messageText; 136 | listItem.appendChild(message); 137 | 138 | listItem.appendChild(children); 139 | 140 | list.appendChild(listItem); 141 | } 142 | 143 | /** 144 | * Append folders. 145 | * @param folders 146 | * @param list 147 | */ 148 | function appendFolders(folders, list) { 149 | while (list.firstChild) { 150 | list.removeChild(list.firstChild); 151 | } 152 | for (let folder of folders) { 153 | appendFolder(folder, list); 154 | } 155 | } 156 | 157 | self.port.on("remove-folder", function (folderID) { 158 | let folder = document.querySelector("#folder-" + folderID); 159 | if (folder) { 160 | let parent = folder.parentNode; 161 | parent.parentNode.removeChild(parent); 162 | } 163 | }); 164 | 165 | self.port.on("children", function (parentID, children) { 166 | let list = document.querySelector("#folder-" + parentID); 167 | appendFolders(children, list); 168 | fetching.delete(parentID); 169 | }); 170 | 171 | self.port.on("init", function (folders, plusIcon, minusIcon, texts) { 172 | recursiveText = texts.recursiveText; 173 | messageText = texts.messageText; 174 | loadingText = texts.loadingText; 175 | addIcon = plusIcon; 176 | removeIcon = minusIcon; 177 | 178 | let rootFolders = document.querySelector("#rootFolders"); 179 | if (rootFolders === null) { 180 | rootFolders = document.createElement("ul"); 181 | rootFolders.id = "rootFolders"; 182 | document.body.appendChild(rootFolders); 183 | } 184 | 185 | appendFolders(folders, rootFolders); 186 | }); 187 | -------------------------------------------------------------------------------- /lib/main.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | const _ = require("sdk/l10n").get; 21 | const {has, set} = require("sdk/preferences/service"); 22 | const self = require("sdk/self"); 23 | const data = self.data; 24 | const simplePrefs = require("sdk/simple-prefs"); 25 | const prefs = simplePrefs.prefs; 26 | const tabs = require("sdk/tabs"); 27 | const {ActionButton} = require("sdk/ui/button/action"); 28 | const windowUtils = require("sdk/window/utils"); 29 | const {setDoNotSortAnnotation, setRecursiveAnnotation} = require("lib/annotations"); 30 | const {BookmarkManager, menuFolder, toolbarFolder, unsortedFolder} = require("lib/bookmarks"); 31 | const bookmarkManager = new BookmarkManager({}); 32 | const {BookmarkSorter} = require("lib/bookmark-sorter"); 33 | const bookmarkSorter = new BookmarkSorter(); 34 | const {showConfigureFoldersToExclude} = require("lib/configure-folders"); 35 | const {getOptionName, setPreferenceMaximum, setPreferenceMinimum} = require("lib/options"); 36 | const sortCriterias = [ 37 | "title", 38 | "url", 39 | "description", 40 | "keyword", 41 | "dateAdded", 42 | "lastModified", 43 | "lastVisited", 44 | "accessCount", 45 | "revurl" 46 | ]; 47 | 48 | /** 49 | * On item added/changed/moved/removed/visited callback. 50 | * @param item 51 | * @param deleted 52 | * @param newFolder 53 | * @param annotationChange 54 | */ 55 | function onChanged(item, deleted, newFolder, annotationChange) { 56 | bookmarkSorter.setChanged(); 57 | } 58 | 59 | /** 60 | * Add the bookmark observer. 61 | */ 62 | function addBookmarkObserver() { 63 | bookmarkManager.on("changed", onChanged); 64 | } 65 | 66 | /** 67 | * Sort all bookmarks. 68 | */ 69 | function sortAllBookmarks() { 70 | bookmarkSorter.setChanged(); 71 | } 72 | 73 | /** 74 | * Remove the bookmark observer. 75 | */ 76 | function removeBookmarkObserver() { 77 | bookmarkManager.removeListener("changed", onChanged); 78 | } 79 | 80 | /** 81 | * Adjust the auto sorting feature. 82 | */ 83 | function adjustAutoSort() { 84 | removeBookmarkObserver(); 85 | if (prefs.auto_sort) { 86 | sortAllBookmarks(); 87 | addBookmarkObserver(); 88 | } 89 | } 90 | 91 | /** 92 | * Adjust the first run preference. 93 | */ 94 | function adjustFirstRun() { 95 | let prefName = getOptionName("firstrun"); 96 | 97 | if (has(prefName)) { 98 | set(prefName, false); 99 | } 100 | else { 101 | set(prefName, true); 102 | prefs.auto_sort = false; 103 | } 104 | } 105 | 106 | /** 107 | * Sort if the auto sort option is on. 108 | */ 109 | function sortIfAuto() { 110 | if (prefs.auto_sort) { 111 | sortAllBookmarks(); 112 | } 113 | } 114 | 115 | /** 116 | * Adjust the sort criteria of the bookmark sorter. 117 | */ 118 | function adjustSortCriteria() { 119 | let differentFolderOrder = prefs.folder_sort_order !== prefs.livemark_sort_order && prefs.folder_sort_order !== prefs.smart_bookmark_sort_order && prefs.folder_sort_order !== prefs.bookmark_sort_order; 120 | bookmarkSorter.setCriteria(sortCriterias[prefs.sort_by], prefs.inverse, 121 | sortCriterias[parseInt(prefs.then_sort_by)] || undefined, prefs.then_inverse, 122 | sortCriterias[parseInt(prefs.folder_sort_by)], prefs.folder_inverse, 123 | differentFolderOrder, prefs.case_insensitive 124 | ); 125 | sortIfAuto(); 126 | } 127 | 128 | /** 129 | * Create the events. 130 | */ 131 | function createEvents() { 132 | simplePrefs.on("auto_sort", function () { 133 | adjustAutoSort(); 134 | }); 135 | 136 | let preferences = ["folder_sort_order", "livemark_sort_order", "smart_bookmark_sort_order", "bookmark_sort_order"]; 137 | 138 | for (let preference of preferences) { 139 | simplePrefs.on(preference, sortIfAuto); 140 | } 141 | 142 | simplePrefs.on("case_insensitive", adjustSortCriteria); 143 | simplePrefs.on("sort_by", adjustSortCriteria); 144 | simplePrefs.on("then_sort_by", adjustSortCriteria); 145 | simplePrefs.on("folder_sort_by", adjustSortCriteria); 146 | simplePrefs.on("inverse", adjustSortCriteria); 147 | simplePrefs.on("then_inverse", adjustSortCriteria); 148 | simplePrefs.on("folder_inverse", adjustSortCriteria); 149 | simplePrefs.on("folder_sort_order", adjustSortCriteria); 150 | simplePrefs.on("livemark_sort_order", adjustSortCriteria); 151 | simplePrefs.on("smart_bookmark_sort_order", adjustSortCriteria); 152 | simplePrefs.on("bookmark_sort_order", adjustSortCriteria); 153 | 154 | simplePrefs.on("exclude_folders", showConfigureFoldersToExclude(sortIfAuto)); 155 | } 156 | 157 | /** 158 | * Show the addon options. 159 | */ 160 | function showOptions() { 161 | windowUtils.getMostRecentBrowserWindow().BrowserOpenAddonsMgr("addons://detail/" + self.id + "/preferences"); 162 | } 163 | 164 | /** 165 | * Show confirmation on install. 166 | */ 167 | function showConfirmation() { 168 | tabs.open({ 169 | url: data.url("confirmation.html"), 170 | onOpen: function (tab) { 171 | tab.on("ready", function () { 172 | let worker = tab.attach({ 173 | contentScriptFile: data.url("confirmation.js") 174 | }); 175 | worker.port.on("button-clicked", function (message) { 176 | switch (message) { 177 | case "button-yes": 178 | prefs.auto_sort = true; 179 | break; 180 | case "button-no": 181 | // Do nothing. 182 | break; 183 | case "button-change-options": 184 | showOptions(); 185 | break; 186 | } 187 | tab.close(); 188 | }); 189 | 190 | worker.port.emit("show", data.url("icon-48.png")); 191 | }); 192 | } 193 | }); 194 | } 195 | 196 | /** 197 | * Create the widgets. 198 | * @param install 199 | */ 200 | function createWidgets(install) { 201 | ActionButton({ 202 | id: "sort-all", 203 | icon: { 204 | 16: "./icon-16.png", 205 | 32: "./icon-32.png", 206 | 64: "./icon-64.png" 207 | }, 208 | label: _("sort_bookmarks"), 209 | onClick: sortAllBookmarks 210 | }); 211 | 212 | if (install) { 213 | showConfirmation(); 214 | } 215 | } 216 | 217 | /** 218 | * Migrate to set the default folder sort order and the default folders to exclude. 219 | * @param upgrade 220 | */ 221 | function migrate(upgrade) { 222 | if (upgrade) { 223 | if (!prefs.migration) { 224 | prefs.migration = "2.7"; 225 | } 226 | 227 | if (prefs.migration < "2.8") { 228 | if ([0, 2, 4, 5].indexOf(prefs.sort_by) >= 0) { 229 | prefs.folder_sort_by = prefs.sort_by; 230 | prefs.folder_inverse = prefs.inverse; 231 | } 232 | 233 | if (prefs.sort_menu === false) { 234 | setDoNotSortAnnotation(menuFolder.id); 235 | setRecursiveAnnotation(menuFolder.id); 236 | } 237 | 238 | if (prefs.sort_toolbar === false) { 239 | setDoNotSortAnnotation(toolbarFolder.id); 240 | setRecursiveAnnotation(toolbarFolder.id); 241 | } 242 | 243 | if (prefs.sort_unsorted === false) { 244 | setDoNotSortAnnotation(unsortedFolder.id); 245 | setRecursiveAnnotation(unsortedFolder.id); 246 | } 247 | 248 | delete prefs.sort_menu; 249 | delete prefs.sort_toolbar; 250 | delete prefs.sort_unsorted; 251 | } 252 | 253 | prefs.migration = self.version; 254 | } 255 | } 256 | 257 | /** 258 | * Set the minimum and maximum of integer preferences. 259 | */ 260 | function setPreferenceMinimumMaximum() { 261 | let preferences = ["folder_sort_order", "livemark_sort_order", "smart_bookmark_sort_order", "bookmark_sort_order"]; 262 | for (let preference of preferences) { 263 | setPreferenceMinimum(preference, 1); 264 | setPreferenceMaximum(preference, 4); 265 | } 266 | 267 | setPreferenceMinimum("folder_delay", 3); 268 | } 269 | 270 | /** 271 | * Auto-sort Bookmarks is a firefox extension that automatically sorts bookmarks. 272 | * @param options 273 | */ 274 | function main(options) { 275 | migrate(options.loadReason === "upgrade"); 276 | adjustFirstRun(); 277 | createWidgets(options.loadReason === "install"); 278 | adjustSortCriteria(); 279 | adjustAutoSort(); 280 | createEvents(); 281 | setPreferenceMinimumMaximum(); 282 | adjustFirstRun(); 283 | } 284 | 285 | exports.main = main; 286 | exports.adjustAutoSort = adjustAutoSort; 287 | exports.adjustSortCriteria = adjustSortCriteria; 288 | exports.createEvents = createEvents; 289 | exports.setPreferenceMinimumMaximum = setPreferenceMinimumMaximum; 290 | -------------------------------------------------------------------------------- /lib/bookmark-sorter.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | const {Class} = require("sdk/core/heritage"); 21 | const {isRecursivelyExcluded} = require("lib/annotations"); 22 | const {Folder, menuFolder, toolbarFolder, unsortedFolder} = require("lib/bookmarks"); 23 | const {setTimeout} = require("sdk/timers"); 24 | const {Cc, Ci} = require("chrome"); 25 | const bookmarkService = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService); 26 | 27 | /** 28 | * Get start time. 29 | * @param name 30 | * @returns {number} 31 | */ 32 | // function getStartTime(name) { 33 | // let now = new Date(); 34 | // return now.getTime(); 35 | // } 36 | 37 | /** 38 | * Get finish time. 39 | * @param name 40 | * @param startTime 41 | */ 42 | // function getFinishTime(name, startTime) { 43 | // let now = new Date(); 44 | // let elapsed = now.getTime() - startTime; 45 | // console.log(name + " (" + elapsed + "ms)"); 46 | // } 47 | 48 | /** 49 | * Reverse the base of an URL to do a better sorting 50 | * @param str 51 | * @return {*} 52 | */ 53 | function reverseBaseUrl(str) { 54 | if (!str) { 55 | return ""; 56 | } 57 | 58 | // Used code generator: https://regex101.com/ 59 | str = str.replace(/^\S+:\/\//, ""); 60 | let re = /^[^\/]+$|^[^\/]+/; 61 | 62 | let m; 63 | 64 | if ((m = re.exec(str)) !== null) { 65 | if (m.index === re.lastIndex) { 66 | re.lastIndex++; 67 | } 68 | 69 | // Replace the found string by it's reversion 70 | str = str.replace(m[0], m[0].split(".").reverse().join(".")); 71 | } 72 | 73 | return str; 74 | } 75 | 76 | /** 77 | * Bookmark sorter class. 78 | */ 79 | let BookmarkSorter = new Class({ 80 | /** 81 | * Indicates if sorting is in progress. 82 | */ 83 | sorting: false, 84 | 85 | /** 86 | * Indicates if there was a change which means a sort is needed. 87 | */ 88 | changed: false, 89 | 90 | /** 91 | * Delay for thread which checks for change. 92 | */ 93 | delay: 3000, 94 | 95 | /** 96 | * Get a bookmark sorter. 97 | * @constructor 98 | */ 99 | initialize: function () { 100 | this.sortIfChanged(); 101 | }, 102 | 103 | /** 104 | * Create a bookmark comparator. 105 | */ 106 | createCompare: function () { 107 | let comparator; 108 | 109 | /** 110 | * Check for corrupted and order flags 111 | * @param bookmark1 112 | * @param bookmark2 113 | * @returns {number} 114 | */ 115 | function checkCorruptedAndOrder(bookmark1, bookmark2) { 116 | if (bookmark1.corrupted) { 117 | if (bookmark2.corrupted) { 118 | return 0; 119 | } 120 | 121 | return 1; 122 | } 123 | else if (bookmark2.corrupted) { 124 | return -1; 125 | } 126 | 127 | if (bookmark1.order !== bookmark2.order) { 128 | return bookmark1.order - bookmark2.order; 129 | } 130 | } 131 | 132 | /** 133 | * Add reverse URLs 134 | * @param bookmark1 135 | * @param bookmark2 136 | * @param criteria 137 | */ 138 | function addReverseUrls(bookmark1, bookmark2, criteria) { 139 | if (criteria === "revurl") { 140 | bookmark1.revurl = reverseBaseUrl(bookmark1.url); 141 | bookmark2.revurl = reverseBaseUrl(bookmark2.url); 142 | } 143 | } 144 | 145 | let compareOptions = { 146 | caseFirst: "upper", 147 | numeric: true, 148 | sensitivity: "case", 149 | }; 150 | 151 | if (BookmarkSorter.prototype.caseInsensitive) { 152 | compareOptions.sensitivity = "base"; 153 | } 154 | 155 | let firstComparator; 156 | if (["title", "url", "revurl", "description", "keyword"].indexOf(BookmarkSorter.prototype.firstSortCriteria) !== -1) { 157 | firstComparator = function (bookmark1, bookmark2) { 158 | addReverseUrls(bookmark1, bookmark2, BookmarkSorter.prototype.firstSortCriteria); 159 | return bookmark1[BookmarkSorter.prototype.firstSortCriteria].localeCompare(bookmark2[BookmarkSorter.prototype.firstSortCriteria], undefined, compareOptions) * BookmarkSorter.prototype.firstReverse; 160 | }; 161 | } 162 | else { 163 | firstComparator = function (bookmark1, bookmark2) { 164 | return (bookmark1[BookmarkSorter.prototype.firstSortCriteria] - bookmark2[BookmarkSorter.prototype.firstSortCriteria]) * BookmarkSorter.prototype.firstReverse; 165 | }; 166 | } 167 | 168 | let secondComparator; 169 | if (BookmarkSorter.prototype.secondSortCriteria !== undefined) { 170 | if (["title", "url", "revurl", "description", "keyword"].indexOf(BookmarkSorter.prototype.secondSortCriteria) !== -1) { 171 | secondComparator = function (bookmark1, bookmark2) { 172 | addReverseUrls(bookmark1, bookmark2, BookmarkSorter.prototype.secondSortCriteria); 173 | return bookmark1[BookmarkSorter.prototype.secondSortCriteria].localeCompare(bookmark2[BookmarkSorter.prototype.secondSortCriteria], undefined, compareOptions) * BookmarkSorter.prototype.secondReverse; 174 | }; 175 | } 176 | else { 177 | secondComparator = function (bookmark1, bookmark2) { 178 | return (bookmark1[BookmarkSorter.prototype.secondSortCriteria] - bookmark2[BookmarkSorter.prototype.secondSortCriteria]) * BookmarkSorter.prototype.secondReverse; 179 | }; 180 | } 181 | } 182 | else { 183 | secondComparator = function () { 184 | return 0; 185 | }; 186 | } 187 | 188 | let itemComparator = function (bookmark1, bookmark2) { 189 | return firstComparator(bookmark1, bookmark2) || secondComparator(bookmark1, bookmark2); 190 | }; 191 | 192 | if (BookmarkSorter.prototype.differentFolderOrder) { 193 | if (BookmarkSorter.prototype.folderSortCriteria !== undefined) { 194 | comparator = function (bookmark1, bookmark2) { 195 | if (bookmark1 instanceof Folder && bookmark2 instanceof Folder) { 196 | if (["title", "description"].indexOf(BookmarkSorter.prototype.folderSortCriteria) !== -1) { 197 | return bookmark1[BookmarkSorter.prototype.folderSortCriteria].localeCompare(bookmark2[BookmarkSorter.prototype.folderSortCriteria], undefined, compareOptions) * BookmarkSorter.prototype.folderReverse; 198 | } 199 | 200 | return (bookmark1[BookmarkSorter.prototype.folderSortCriteria] - bookmark2[BookmarkSorter.prototype.folderSortCriteria]) * BookmarkSorter.prototype.folderReverse; 201 | } 202 | 203 | return itemComparator(bookmark1, bookmark2); 204 | }; 205 | } 206 | else { 207 | comparator = function (bookmark1, bookmark2) { 208 | if (bookmark1 instanceof Folder && bookmark2 instanceof Folder) { 209 | return 0; 210 | } 211 | 212 | return itemComparator(bookmark1, bookmark2); 213 | }; 214 | } 215 | } 216 | else { 217 | comparator = itemComparator; 218 | } 219 | 220 | return function (bookmark1, bookmark2) { 221 | let result = checkCorruptedAndOrder(bookmark1, bookmark2); 222 | if (result === undefined) { 223 | return comparator(bookmark1, bookmark2); 224 | } 225 | 226 | return result; 227 | }; 228 | }, 229 | 230 | /** 231 | * Sort all bookmarks. 232 | */ 233 | sortAllBookmarks: function () { 234 | let p1 = new Promise((resolve) => { 235 | let folders = []; 236 | 237 | if (!isRecursivelyExcluded(menuFolder.id)) { 238 | folders.push(menuFolder); 239 | 240 | for (let f of menuFolder.getFolders()) { 241 | folders.push(f); 242 | } 243 | } 244 | 245 | resolve(folders); 246 | }); 247 | 248 | let p2 = new Promise((resolve) => { 249 | let folders = []; 250 | 251 | if (!isRecursivelyExcluded(toolbarFolder.id)) { 252 | folders.push(toolbarFolder); 253 | 254 | for (let f of toolbarFolder.getFolders()) { 255 | folders.push(f); 256 | } 257 | } 258 | 259 | resolve(folders); 260 | }); 261 | 262 | let p3 = new Promise((resolve) => { 263 | let folders = []; 264 | 265 | if (!isRecursivelyExcluded(unsortedFolder.id)) { 266 | folders.push(unsortedFolder); 267 | 268 | for (let f of unsortedFolder.getFolders()) { 269 | folders.push(f); 270 | } 271 | } 272 | 273 | resolve(folders); 274 | }); 275 | 276 | Promise.all([p1, p2, p3]).then(folders => { 277 | // Flatten array of arrays into array 278 | let merged = [].concat.apply([], folders); 279 | this.sortFolders(merged); 280 | }); 281 | }, 282 | 283 | /** 284 | * Set the sort criteria. 285 | * @param {string} firstSortCriteria The first sort criteria attribute. 286 | * @param {boolean} firstReverse Whether the first sort is reversed. 287 | * @param {string} secondReverse The second sort criteria attribute. 288 | * @param secondSortCriteria 289 | * @param folderSortCriteria 290 | * @param folderReverse 291 | * @param differentFolderOrder 292 | * @param caseInsensitive 293 | */ 294 | setCriteria: function (firstSortCriteria, firstReverse, secondSortCriteria, secondReverse, folderSortCriteria, folderReverse, differentFolderOrder, caseInsensitive) { 295 | BookmarkSorter.prototype.firstReverse = firstReverse ? -1 : 1; 296 | BookmarkSorter.prototype.firstSortCriteria = firstSortCriteria; 297 | BookmarkSorter.prototype.secondReverse = secondReverse ? -1 : 1; 298 | BookmarkSorter.prototype.secondSortCriteria = secondSortCriteria; 299 | BookmarkSorter.prototype.folderReverse = folderReverse ? -1 : 1; 300 | BookmarkSorter.prototype.folderSortCriteria = folderSortCriteria; 301 | BookmarkSorter.prototype.differentFolderOrder = differentFolderOrder; 302 | BookmarkSorter.prototype.caseInsensitive = caseInsensitive; 303 | this.compare = this.createCompare(); 304 | }, 305 | 306 | /** 307 | * Sort and save a folder. 308 | * @param {Folder} folder The folder to sort and save. 309 | */ 310 | sortAndSave: function (folder) { 311 | if (folder.canBeSorted()) { 312 | let self = this; 313 | self.sortFolder(folder); 314 | bookmarkService.runInBatchMode({ 315 | runBatched() { 316 | folder.save(); 317 | }, 318 | }, null); 319 | } 320 | }, 321 | 322 | /** 323 | * Sort the `folder` children. 324 | * @param {Folder} folder The folder to sort. 325 | */ 326 | sortFolder: function (folder) { 327 | folder.getChildren(); 328 | 329 | let delta = 0; 330 | let length; 331 | 332 | for (let i = 0; i < folder.children.length; ++i) { 333 | folder.children[i].sort(this.compare); 334 | length = folder.children[i].length; 335 | for (let j = 0; j < length; ++j) { 336 | folder.children[i][j].setIndex(j + delta); 337 | } 338 | 339 | delta += length + 1; 340 | } 341 | }, 342 | 343 | /** 344 | * Sort the `folders`. 345 | * @param {Array.|Folder} folders The folders to sort. 346 | */ 347 | sortFolders: function (folders) { 348 | folders = folders instanceof Folder ? [folders] : folders; 349 | 350 | let self = this; 351 | let promiseAry = []; 352 | 353 | for (let folder of folders) { 354 | let p = new Promise((resolve) => { 355 | // Not obvious but arg1 = folder 356 | setTimeout((function (arg1) { 357 | return function () { 358 | self.sortAndSave(arg1); 359 | resolve(true); 360 | }; 361 | }(folder)), 0); 362 | }); 363 | promiseAry.push(p); 364 | } 365 | 366 | Promise.all(promiseAry).then(bool => { 367 | if (bool) { 368 | self.sorting = false; 369 | self.changed = false; 370 | } 371 | }); 372 | }, 373 | 374 | /** 375 | * Set flag to trigger sorting. 376 | */ 377 | setChanged: function () { 378 | this.changed = true; 379 | }, 380 | 381 | /** 382 | * Perform sorting only if there was a change and not already sorting. 383 | */ 384 | sortIfChanged: function () { 385 | if (this.changed && !this.sorting) { 386 | this.sorting = true; 387 | this.sortAllBookmarks(); 388 | } 389 | 390 | let self = this; 391 | 392 | setTimeout(function () { 393 | self.sortIfChanged(); 394 | }, this.delay); 395 | }, 396 | 397 | }); 398 | 399 | exports.BookmarkSorter = BookmarkSorter; 400 | -------------------------------------------------------------------------------- /test/utils.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | const {Cc, Ci, Cu} = require("chrome"); 21 | const {defer} = require("sdk/core/promise"); 22 | const {MENU, TOOLBAR, UNSORTED} = require("sdk/places/bookmarks"); 23 | const {reset} = require("sdk/preferences/service"); 24 | const self = require("sdk/self"); 25 | const windows = require("sdk/windows").browserWindows; 26 | const windowUtils = require("sdk/window/utils"); 27 | const annotationService = Cc["@mozilla.org/browser/annotation-service;1"].getService(Ci.nsIAnnotationService); 28 | const asyncHistory = Cc["@mozilla.org/browser/history;1"].getService(Ci.mozIAsyncHistory); 29 | const bookmarkService = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService); 30 | const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); 31 | const {Bookmark, Folder, Livemark, menuFolder, Separator, SmartBookmark, toolbarFolder, unsortedFolder} = require("lib/bookmarks"); 32 | const descriptionAnnotation = "bookmarkProperties/description"; 33 | const livemarkFeedAnnotation = "livemark/feedURI"; 34 | const livemarkReadOnlyAnnotation = "placesInternal/READ_ONLY"; 35 | const livemarkSiteAnnotation = "livemark/siteURI"; 36 | const smartBookmarkAnnotation = "Places/SmartBookmark"; 37 | const {removeDoNotSortAnnotation, removeRecursiveAnnotation, setDoNotSortAnnotation, setRecursiveAnnotation} = require("lib/annotations"); 38 | 39 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 40 | XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", "resource://gre/modules/PlacesUtils.jsm"); 41 | 42 | function ignore(folder) { 43 | setDoNotSortAnnotation(folder.id); 44 | setRecursiveAnnotation(folder.id); 45 | } 46 | 47 | function sort(folder) { 48 | removeDoNotSortAnnotation(folder.id); 49 | removeRecursiveAnnotation(folder.id); 50 | } 51 | 52 | function bookmarkToString(bookmark) { 53 | return bookmark.id + ". " + bookmark.title; 54 | } 55 | 56 | /** 57 | * Assert the equality of the bookmarks array/generator. 58 | * @param {Function|Array.} bookmarks1 The actual bookmarks. 59 | * @param {Function|Array.} bookmarks2 The expected bookmarks. 60 | */ 61 | function assertBookmarksArray(assert, bookmarks1, bookmarks2) { 62 | let generatedBookmarks1 = []; 63 | for (let value of bookmarks1) { 64 | generatedBookmarks1.push(value); 65 | } 66 | 67 | let generatedBookmarks2 = []; 68 | for (let value of bookmarks2) { 69 | generatedBookmarks2.push(value); 70 | } 71 | 72 | let equality = true; 73 | if (generatedBookmarks1.length === generatedBookmarks2.length) { 74 | for (let i = 0; i < generatedBookmarks1.length; ++i) { 75 | equality = equality && generatedBookmarks1[i].id === generatedBookmarks2[i].id && generatedBookmarks1[i].title === generatedBookmarks2[i].title && generatedBookmarks1[i].url === generatedBookmarks2[i].url; 76 | } 77 | } 78 | else { 79 | equality = false; 80 | } 81 | 82 | let bookmarks1String = JSON.stringify(generatedBookmarks1.map(bookmarkToString)); 83 | let bookmarks2String = JSON.stringify(generatedBookmarks2.map(bookmarkToString)); 84 | assert.ok(equality, "\nResult: " + (generatedBookmarks1.length > 0 ? bookmarks1String : "[]") + "\n !==\nExpected: " + (generatedBookmarks2.length > 0 ? bookmarks2String : "[]")); 85 | } 86 | 87 | /** 88 | * Create, save and get a new bookmark. 89 | * @param {string} title The bookmark name. 90 | * @param {string} url The bookmark URL. 91 | * @param {Folder} parent The parent folder. 92 | * @param {int} index The bookmark index. 93 | * @return {Bookmark} The new bookmark. 94 | */ 95 | function createBookmark(title, url, parent, index) { 96 | index = index !== undefined ? index : bookmarkService.DEFAULT_INDEX; 97 | let itemID = bookmarkService.insertBookmark(parent.id, ioService.newURI(url, null, null), index, title); 98 | return new Bookmark(itemID, index, parent.id, title, undefined, undefined, url); 99 | } 100 | 101 | /** 102 | * Create, save and get a new folder. 103 | * @param {string} title The folder name. 104 | * @param {Folder} parent The parent folder. 105 | * @param {int} index The folder index. 106 | * @return {Folder} The new folder. 107 | */ 108 | function createFolder(title, parent, index) { 109 | index = index !== undefined ? index : bookmarkService.DEFAULT_INDEX; 110 | let itemID = bookmarkService.createFolder(parent.id, title, index); 111 | return new Folder(itemID, index, parent.id, title); 112 | } 113 | 114 | /** 115 | * Create, save and get a new livemark. 116 | * @param {string} title The livemark name. 117 | * @param {string} url The livemark feed URL. 118 | * @param {Folder} parent The parent folder. 119 | * @param {int} index The livemark index. 120 | * @return {Livemark} The new livemark. 121 | */ 122 | function createLivemark(title, url, parent, index) { 123 | index = index !== undefined ? index : bookmarkService.DEFAULT_INDEX; 124 | let itemID = bookmarkService.createFolder(parent.id, title, index); 125 | annotationService.setItemAnnotation(itemID, livemarkFeedAnnotation, url, 0, Ci.nsIAnnotationService.EXPIRE_NEVER); 126 | annotationService.setItemAnnotation(itemID, livemarkReadOnlyAnnotation, 1, 0, Ci.nsIAnnotationService.EXPIRE_NEVER); 127 | annotationService.setItemAnnotation(itemID, livemarkSiteAnnotation, url, 0, Ci.nsIAnnotationService.EXPIRE_NEVER); 128 | return new Livemark(itemID, index, parent.id, title); 129 | } 130 | 131 | /** 132 | * Create, save and get a new separator. 133 | * @param {Folder} parent The parent folder. 134 | * @param {int} index The separator index. 135 | * @return {Separator} The new separator. 136 | */ 137 | function createSeparator(parent, index) { 138 | index = index !== undefined ? index : bookmarkService.DEFAULT_INDEX; 139 | let itemID = bookmarkService.insertSeparator(parent.id, index); 140 | return new Separator(itemID, index, parent.id); 141 | } 142 | 143 | /** 144 | * Create, save and get a new bookmark. 145 | * @param {string} title The bookmark name. 146 | * @param {string} smartBookmarkValue The smart bookmark value. 147 | * @param {string} url The bookmark URL. 148 | * @param {Folder} parent The parent folder. 149 | * @param {int} index The bookmark index. 150 | * @return {Bookmark} The new bookmark. 151 | */ 152 | function createSmartBookmark(title, smartBookmarkValue, url, parent, index) { 153 | index = index !== undefined ? index : bookmarkService.DEFAULT_INDEX; 154 | let itemID = bookmarkService.insertBookmark(parent.id, ioService.newURI(url, null, null), index, title); 155 | annotationService.setItemAnnotation(itemID, smartBookmarkAnnotation, smartBookmarkValue, 0, Ci.nsIAnnotationService.EXPIRE_NEVER); 156 | return new SmartBookmark(itemID, index, parent.id, title); 157 | } 158 | 159 | /** 160 | * Delete `item`. 161 | * @param {Item} item The item to delete. 162 | */ 163 | function deleteItem(item) { 164 | bookmarkService.removeItem(item.id); 165 | } 166 | 167 | /** 168 | * Get all the folders as a flat list. 169 | * @return {Array.} The folders. 170 | */ 171 | function getAllFolders() { 172 | let folders = []; 173 | 174 | folders.push(menuFolder); 175 | 176 | folders.push(toolbarFolder); 177 | 178 | folders.push(unsortedFolder); 179 | 180 | for (let i = 0, length = folders.length; i < length; ++i) { 181 | for (let folder of folders[i].getFolders()) { 182 | folders.push(folder); 183 | } 184 | } 185 | 186 | return folders; 187 | } 188 | 189 | /** 190 | * Delete all bookmarks. 191 | */ 192 | function deleteAllBookmarks() { 193 | let folders = getAllFolders(); 194 | let id; 195 | for (let folder of folders) { 196 | while (folder.getChildren().length > 1 || folder.getChildren()[0].length > 0) { 197 | for (let i = 0; i <= folder.getChildren()[0].length; ++i) { 198 | id = bookmarkService.getIdForItemAt(folder.id, i); 199 | if (id > -1) { 200 | bookmarkService.removeItem(id); 201 | } 202 | } 203 | } 204 | } 205 | 206 | sort(MENU); 207 | sort(TOOLBAR); 208 | sort(UNSORTED); 209 | } 210 | 211 | /** 212 | * Get the option long name from the `shortName`. 213 | * @param {string} The short name. 214 | * @return {string} The long name. 215 | */ 216 | function getOptionName(shortName) { 217 | return "extensions." + self.id + "." + shortName; 218 | } 219 | 220 | /** 221 | * Move `item` to `newIndex`. 222 | * @param {Item} item The item to move. 223 | * @param {int} newIndex The new item position. 224 | * @param {int} parent The new parent. 225 | */ 226 | function move(item, newIndex, parent) { 227 | if (parent !== undefined) { 228 | item.parentID = parent.id; 229 | } 230 | 231 | bookmarkService.moveItem(item.id, item.parentID, newIndex); 232 | } 233 | 234 | /** 235 | * Open an new window. 236 | */ 237 | function openWindow() { 238 | let deferred = defer(); 239 | 240 | windows.open({ 241 | onOpen: function () { 242 | deferred.resolve(); 243 | }, 244 | 245 | url: "", 246 | }); 247 | 248 | return deferred.promise; 249 | } 250 | 251 | /** 252 | * Print the `folder` children. 253 | * @param {Folder} folder The folder to print. 254 | */ 255 | function printFolder(folder) { 256 | for (let bookmark of folder.getChildren()[0]) { 257 | console.log(bookmark.title); 258 | } 259 | } 260 | 261 | /** 262 | * Get an array of `count` numbers. 263 | * @param {int} count The new array length. 264 | * @return {Array.} The new array of numbers. 265 | */ 266 | function range(count) { 267 | let array = []; 268 | for (let i = 0; i < count; ++i) { 269 | array.push(i); 270 | } 271 | 272 | return array; 273 | } 274 | 275 | /** 276 | * Rename `item` to `newName`. 277 | * @param {Item} item The item to rename. 278 | * @param {string} newName The new name. 279 | */ 280 | function rename(item, newName) { 281 | item.title = newName; 282 | bookmarkService.setItemTitle(item.id, newName); 283 | } 284 | 285 | /** 286 | * Reset the preferences to their default value. 287 | */ 288 | function resetPreferences() { 289 | let preferences = ["auto_sort", "delay", "folder_delay", "sort_menu", "sort_toolbar", "sort_unsorted", "sort_by", "inverse", "then_sort_by", "then_inverse", "folder_sort_order", "livemark_sort_order", "smart_bookmark_sort_order", "bookmark_sort_order", "show_tools_menu_item", "show_bookmarks_menu_item", "show_bookmarks_toolbar_menu_item", "show_bookmarks_manager_menu_item"]; 290 | for (let preference of preferences) { 291 | reset(getOptionName(preference)); 292 | } 293 | } 294 | 295 | /** 296 | * Set the `item` `dateAdded`. 297 | * @param {Item} item The item. 298 | * @param {int} dateAdded The new date added time. 299 | */ 300 | function setDateAdded(item, dateAdded) { 301 | bookmarkService.setItemDateAdded(item.id, dateAdded); 302 | } 303 | 304 | /** 305 | * Set the `item` `description`. 306 | * @param {Item} item The item. 307 | * @param {string} description The new description. 308 | */ 309 | function setDescription(item, description) { 310 | try { 311 | annotationService.setItemAnnotation(item.id, descriptionAnnotation, description, 0, Ci.nsIAnnotationService.EXPIRE_NEVER); 312 | } 313 | catch (exception) { 314 | console.log("Cannot set description on item " + item.id + "."); 315 | } 316 | } 317 | 318 | /** 319 | * Set the `item` `keyword`. 320 | * @param {Item} item The item. 321 | * @param {string} keyword The new keyword. 322 | */ 323 | function setKeyword(item, keyword) { 324 | return PlacesUtils.keywords.insert({ 325 | keyword: keyword, 326 | url: item.url, 327 | }); 328 | } 329 | 330 | /** 331 | * Set the `item` `lastModified`. 332 | * @param {Item} item The item. 333 | * @param {int} lastModified The new last modified time. 334 | */ 335 | function setLastModified(item, lastModified) { 336 | bookmarkService.setItemLastModified(item.id, lastModified); 337 | } 338 | 339 | /** 340 | * Set the `visits` the `item`. 341 | * @param {Item} item The item. 342 | * @param {Array.|int} visits The visit times. 343 | */ 344 | function setVisits(item, visits) { 345 | let deferred = defer(); 346 | 347 | if (visits.length === undefined) { 348 | visits = [visits]; 349 | } 350 | 351 | for (let index in visits) { 352 | if (visits.hasOwnProperty(index)) { 353 | visits[index] = { 354 | referrerURI: undefined, 355 | transitionType: Ci.nsINavHistoryService.TRANSITION_LINK, 356 | visitDate: visits[index] * 1000, 357 | }; 358 | } 359 | } 360 | 361 | asyncHistory.updatePlaces({ 362 | title: item.title, 363 | uri: ioService.newURI(item.url, null, null), 364 | visits: visits, 365 | }, { 366 | handleCompletion: function () { 367 | deferred.resolve(); 368 | }, 369 | 370 | handleResult: function () { 371 | }, 372 | }); 373 | 374 | return deferred.promise; 375 | } 376 | 377 | function showBookmarksManager() { 378 | let deferred = defer(); 379 | 380 | let window = windowUtils.getMostRecentWindow(); 381 | let bookmarksManager = windowUtils.getMostRecentWindow("Places:Organizer"); 382 | if (bookmarksManager === null) { 383 | bookmarksManager = window.openDialog("chrome://browser/content/places/places.xul", "", "chrome,toolbar=yes,dialog=no,resizable", "AllBookmarks"); 384 | 385 | bookmarksManager.addEventListener("load", function () { 386 | deferred.resolve(bookmarksManager); 387 | }, false); 388 | } 389 | else { 390 | bookmarksManager.PlacesOrganizer.selectLeftPaneQuery("AllBookmarks"); 391 | bookmarksManager.focus(); 392 | 393 | deferred.resolve(bookmarksManager); 394 | } 395 | 396 | return deferred.promise; 397 | } 398 | 399 | exports.assertBookmarksArray = assertBookmarksArray; 400 | exports.createBookmark = createBookmark; 401 | exports.createFolder = createFolder; 402 | exports.createLivemark = createLivemark; 403 | exports.createSeparator = createSeparator; 404 | exports.createSmartBookmark = createSmartBookmark; 405 | exports.deleteAllBookmarks = deleteAllBookmarks; 406 | exports.deleteItem = deleteItem; 407 | exports.getOptionName = getOptionName; 408 | exports.ignore = ignore; 409 | exports.move = move; 410 | exports.openWindow = openWindow; 411 | exports.printFolder = printFolder; 412 | exports.range = range; 413 | exports.rename = rename; 414 | exports.resetPreferences = resetPreferences; 415 | exports.setDateAdded = setDateAdded; 416 | exports.setDescription = setDescription; 417 | exports.setKeyword = setKeyword; 418 | exports.setLastModified = setLastModified; 419 | exports.setVisits = setVisits; 420 | exports.showBookmarksManager = showBookmarksManager; 421 | exports.sort = sort; 422 | -------------------------------------------------------------------------------- /lib/bookmarks.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | const {Class} = require("sdk/core/heritage"); 21 | const {emit} = require("sdk/event/core"); 22 | const {EventTarget} = require("sdk/event/target"); 23 | const _ = require("sdk/l10n").get; 24 | const {prefs} = require("sdk/simple-prefs"); 25 | const {when} = require("sdk/system/unload"); 26 | const {merge} = require("sdk/util/object"); 27 | const {Cc, Ci, Cu} = require("chrome"); 28 | const bookmarkService = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService); 29 | const historyService = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService); 30 | const {getDescription, hasDoNotSortAnnotation, hasRecursiveAnnotation, isRecursivelyExcluded, isLivemark, isSmartBookmark} = require("lib/annotations"); 31 | 32 | Cu.import("resource://gre/modules/XPCOMUtils.jsm", this); 33 | 34 | /** 35 | * Item class. Base class for bookmarks/folders/separators/live bookmarks/smart bookmarks. 36 | */ 37 | let Item = new Class({ 38 | /** 39 | * Get an item. 40 | * @constructor 41 | * @param itemID 42 | * @param index 43 | * @param parentID 44 | */ 45 | initialize: function (itemID, index, parentID) { 46 | this.id = itemID; 47 | this.setIndex(index); 48 | this.parentID = parentID; 49 | }, 50 | 51 | /** 52 | * Get the parent folder. 53 | * @return {Item} The parent folder. 54 | */ 55 | getFolder: function () { 56 | return createItem(bookmarkService.TYPE_FOLDER, this.parentID); 57 | }, 58 | 59 | /** 60 | * Save the new index. 61 | */ 62 | saveIndex: function () { 63 | try { 64 | bookmarkService.setItemIndex(this.id, this.index); 65 | } 66 | catch (exception) { 67 | // console.error("failed to move " + this.id + ". " + this.title + " to " + this.index + " (" + this.url + ")"); 68 | } 69 | }, 70 | 71 | /** 72 | * Set the new `index` saving the old index. 73 | * @param {int} index The new index. 74 | */ 75 | setIndex: function (index) { 76 | this.oldIndex = this.index || index; 77 | this.index = index; 78 | }, 79 | }); 80 | 81 | /** 82 | * Bookmark class. 83 | * @extends Item 84 | */ 85 | let Bookmark = new Class({ 86 | extends: Item, 87 | 88 | /** 89 | * Get a bookmark. 90 | * @param {int} itemID The bookmark identifier. 91 | * @param {int} index The bookmark position. 92 | * @param {int} parentID The bookmark parent identifier. 93 | * @param {string} title The bookmark title. 94 | * @param {string} url The item URL. 95 | * @param {int} lastVisited The timestamp of the last visit. 96 | * @param {int} accessCount The access count. 97 | * @param {int} dateAdded The timestamp of the date added. 98 | * @param {int} lastModified The timestamp of the last modified date. 99 | * @constructor 100 | */ 101 | initialize: function (itemID, index, parentID, title, dateAdded, lastModified, url, lastVisited, accessCount) { 102 | if (title === null || dateAdded === null || lastModified === null || url === null || lastVisited === null || accessCount === null) { 103 | // console.error("Corrupted bookmark found. ID: " + itemID + " - Title: " + title + " - URL: " + url); 104 | this.corrupted = true; 105 | } 106 | 107 | Item.prototype.initialize.call(this, itemID, index, parentID); 108 | this.title = title || ""; 109 | this.url = url || ""; 110 | this.lastVisited = lastVisited || 0; 111 | this.accessCount = accessCount || 0; 112 | this.dateAdded = dateAdded || 0; 113 | this.lastModified = lastModified || 0; 114 | this.order = prefs.bookmark_sort_order || 4; 115 | this.description = getDescription(this) || ""; 116 | this.setKeyword(); 117 | }, 118 | 119 | /** 120 | * Fetch the keyword and set it to the current bookmark. 121 | */ 122 | setKeyword: function () { 123 | let keyword = ""; 124 | try { 125 | keyword = bookmarkService.getKeywordForBookmark(this.id); 126 | keyword = keyword || ""; 127 | } 128 | catch (exception) { 129 | // Nothing to do. 130 | } 131 | 132 | this.keyword = keyword; 133 | }, 134 | }); 135 | 136 | /** 137 | * Determine if bookmark exists. 138 | * @param itemID 139 | * @returns {boolean} 140 | */ 141 | Bookmark.exists = function (itemID) { 142 | return bookmarkService.getItemIndex(itemID) >= 0; 143 | }; 144 | 145 | /** 146 | * Bookmark manager class. 147 | * @extends EventTarget 148 | */ 149 | let BookmarkManager = new Class({ 150 | extends: EventTarget, 151 | 152 | /** 153 | * Create a new bookmark observer. 154 | * @constructor 155 | * @param options 156 | */ 157 | initialize: function initialize(options) { 158 | EventTarget.prototype.initialize.call(this, options); 159 | merge(this, options); 160 | this.createObserver(); 161 | }, 162 | 163 | /** 164 | * Create a bookmark observer. 165 | */ 166 | createObserver: function () { 167 | let self = this; 168 | 169 | let bookmarkObserver = { 170 | onItemAdded: function () { 171 | emit(self, "changed"); 172 | }, 173 | 174 | onItemChanged: function () { 175 | emit(self, "changed"); 176 | }, 177 | 178 | onItemMoved: function () { 179 | emit(self, "changed"); 180 | }, 181 | 182 | onItemRemoved: function (itemID, parentID, index, itemType) { 183 | if (itemType === 3) { 184 | emit(self, "changed"); 185 | } 186 | }, 187 | 188 | onItemVisited: function () { 189 | emit(self, "changed"); 190 | }, 191 | 192 | QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]), 193 | }; 194 | 195 | BookmarkManager.prototype.observers.push(bookmarkObserver); 196 | bookmarkService.addObserver(bookmarkObserver, false); 197 | }, 198 | }); 199 | 200 | BookmarkManager.prototype.observers = []; 201 | 202 | /** 203 | * Separator class. 204 | * @extends Item 205 | */ 206 | let Separator = new Class({ 207 | extends: Item, 208 | 209 | /** 210 | * Get a separator. 211 | * @param {int} itemID The separator identifier. 212 | * @param {int} index The separator position. 213 | * @param {int} parentID The separator parent identifier. 214 | * @constructor 215 | */ 216 | initialize: function (itemID, index, parentID) { 217 | Item.prototype.initialize.call(this, itemID, index, parentID); 218 | }, 219 | }); 220 | 221 | /** 222 | * Folder class. 223 | * @extends Bookmark 224 | */ 225 | let Folder = new Class({ 226 | extends: Bookmark, 227 | 228 | /** 229 | * Get an existing folder. 230 | * @constructor 231 | * @param {int} itemID The folder identifier. 232 | * @param {int} index The folder position. 233 | * @param {int} parentID The folder parent identifier. 234 | * @param {string} title The folder title. 235 | * @param dateAdded 236 | * @param lastModified 237 | */ 238 | initialize: function (itemID, index, parentID, title, dateAdded, lastModified) { 239 | Bookmark.prototype.initialize.call(this, itemID, index, parentID, title, dateAdded, lastModified); 240 | this.order = prefs.folder_sort_order || 1; 241 | }, 242 | 243 | /** 244 | * Check if this folder can be sorted. 245 | * @return {boolean} Whether it can be sorted or not. 246 | */ 247 | canBeSorted: function () { 248 | if (hasDoNotSortAnnotation(this.id) || this.hasAncestorExcluded()) { 249 | return false; 250 | } 251 | 252 | return !this.isRoot(); 253 | }, 254 | 255 | /** 256 | * Get the immediate children. 257 | * @return {Array.} The children. 258 | */ 259 | getChildren: function () { 260 | let index = 0; 261 | 262 | this.children = [[]]; 263 | 264 | let options = historyService.getNewQueryOptions(); 265 | options.queryType = historyService.QUERY_TYPE_BOOKMARKS; 266 | 267 | let query = historyService.getNewQuery(); 268 | query.setFolders([this.id], 1); 269 | 270 | let result = historyService.executeQuery(query, options); 271 | 272 | let rootNode = result.root; 273 | rootNode.containerOpen = true; 274 | 275 | for (let i = 0; i < rootNode.childCount; ++i) { 276 | let node = rootNode.getChild(i); 277 | let item = createItemFromNode(node, this.id); 278 | if (item instanceof Separator) { 279 | this.children.push([]); 280 | ++index; 281 | } 282 | else if (item !== undefined) { 283 | this.children[index].push(item); 284 | } 285 | } 286 | 287 | rootNode.containerOpen = false; 288 | 289 | return this.children; 290 | }, 291 | 292 | /** 293 | * Get folders recursively. 294 | */ 295 | getFolders: function () { 296 | let folders = []; 297 | let folder; 298 | let node; 299 | 300 | let options = historyService.getNewQueryOptions(); 301 | options.excludeItems = true; 302 | options.excludeQueries = true; 303 | options.queryType = historyService.QUERY_TYPE_BOOKMARKS; 304 | 305 | let query = historyService.getNewQuery(); 306 | query.setFolders([this.id], 1); 307 | 308 | let result = historyService.executeQuery(query, options); 309 | 310 | let rootNode = result.root; 311 | rootNode.containerOpen = true; 312 | 313 | for (let i = 0; i < rootNode.childCount; ++i) { 314 | node = rootNode.getChild(i); 315 | 316 | if (!isRecursivelyExcluded(node.itemId)) { 317 | folder = new Folder(node.itemId, node.bookmarkIndex, this.id, node.title, node.dateAdded, node.lastModified); 318 | 319 | if (!isLivemark(folder.id)) { 320 | folders.push(folder); 321 | 322 | for (let f of folder.getFolders()) { 323 | folders.push(f); 324 | } 325 | } 326 | } 327 | } 328 | 329 | rootNode.containerOpen = false; 330 | 331 | return folders; 332 | }, 333 | 334 | /** 335 | * Check if this folder has an ancestor that is recursively excluded. 336 | */ 337 | hasAncestorExcluded: function () { 338 | if (isRecursivelyExcluded(this.id)) { 339 | return true; 340 | } 341 | else { 342 | let parentID = bookmarkService.getFolderIdForItem(this.id); 343 | if (parentID > 0) { 344 | let parentFolder = createItem(bookmarkService.TYPE_FOLDER, parentID); 345 | return parentFolder.hasAncestorExcluded(); 346 | } 347 | } 348 | 349 | return false; 350 | }, 351 | 352 | /** 353 | * Check if this folder is a root folder (menu, toolbar, unsorted). 354 | * @return {boolean} Whether this is a root folder or not. 355 | */ 356 | isRoot: function () { 357 | return this.id === bookmarkService.placesRoot; 358 | }, 359 | 360 | /** 361 | * Check if at least one children has moved. 362 | * @return {boolean} Whether at least one children has moved or not. 363 | */ 364 | hasMove: function () { 365 | for (let i = 0; i < this.children.length; ++i) { 366 | let length = this.children[i].length; 367 | for (let j = 0; j < length; ++j) { 368 | if (this.children[i][j].index !== this.children[i][j].oldIndex) { 369 | return true; 370 | } 371 | } 372 | } 373 | 374 | return false; 375 | }, 376 | 377 | /** 378 | * Save the new children positions. 379 | */ 380 | save: function () { 381 | if (this.hasMove()) { 382 | for (let i = 0; i < this.children.length; ++i) { 383 | let length = this.children[i].length; 384 | for (let j = 0; j < length; ++j) { 385 | this.children[i][j].saveIndex(); 386 | } 387 | } 388 | } 389 | }, 390 | }); 391 | 392 | /** 393 | * Livemark class. 394 | * @extends Bookmark 395 | */ 396 | let Livemark = new Class({ 397 | extends: Bookmark, 398 | 399 | /** 400 | * Get an existing smart bookmark. 401 | * @param {int} itemID The folder identifier. 402 | * @param {int} index The folder position. 403 | * @param {int} parentID The folder parent identifier. 404 | * @param {string} title The folder title. 405 | * @constructor 406 | * @param dateAdded 407 | * @param lastModified 408 | */ 409 | initialize: function (itemID, index, parentID, title, dateAdded, lastModified) { 410 | Bookmark.prototype.initialize.call(this, itemID, index, parentID, title, dateAdded, lastModified); 411 | this.order = prefs.livemark_sort_order || 2; 412 | }, 413 | }); 414 | 415 | /** 416 | * Smart bookmark class. 417 | * @extends Bookmark 418 | */ 419 | let SmartBookmark = new Class({ 420 | extends: Bookmark, 421 | 422 | /** 423 | * Get an existing smart bookmark. 424 | * @constructor 425 | * @param {int} itemID The folder identifier. 426 | * @param {int} index The folder position. 427 | * @param {int} parentID The folder parent identifier. 428 | * @param {string} title The folder title. 429 | */ 430 | initialize: function (itemID, index, parentID, title) { 431 | Bookmark.prototype.initialize.call(this, itemID, index, parentID, title); 432 | this.order = prefs.smart_bookmark_sort_order || 3; 433 | }, 434 | }); 435 | 436 | /** 437 | * Create an item from the `type`. 438 | * @param {int} type The item type. 439 | * @param {int} itemID The item ID. 440 | * @param {int} parentID The parent ID. 441 | * @param {string} title The item title. 442 | * @param {string} url The item URL. 443 | * @param {int} lastVisited The timestamp of the last visit. 444 | * @param {int} accessCount The access count. 445 | * @param {int} dateAdded The timestamp of the date added. 446 | * @param {int} lastModified The timestamp of the last modified date. 447 | * @return {*} The new item. 448 | * @param index 449 | */ 450 | function createItem(type, itemID, index, parentID, title, url, lastVisited, accessCount, dateAdded, lastModified) { 451 | let item; 452 | switch (type) { 453 | case bookmarkService.TYPE_BOOKMARK: 454 | if (isSmartBookmark(itemID)) { 455 | item = new SmartBookmark(itemID, index, parentID, title); 456 | } 457 | else { 458 | item = new Bookmark(itemID, index, parentID, title, dateAdded, lastModified, url, lastVisited, accessCount); 459 | } 460 | 461 | break; 462 | case bookmarkService.TYPE_FOLDER: 463 | if (isLivemark(itemID)) { 464 | item = new Livemark(itemID, index, parentID, title, dateAdded, lastModified); 465 | } 466 | else { 467 | item = new Folder(itemID, index, parentID, title, dateAdded, lastModified); 468 | } 469 | 470 | break; 471 | case bookmarkService.TYPE_SEPARATOR: 472 | item = new Separator(itemID, index, parentID); 473 | break; 474 | } 475 | 476 | return item; 477 | } 478 | 479 | /** 480 | * Create an item from the `node` type. 481 | * @param {object} node The node item. 482 | * @param {int} parentID The parent ID. 483 | * @return {Item} The new item. 484 | */ 485 | function createItemFromNode(node, parentID) { 486 | let type; 487 | switch (node.type) { 488 | case node.RESULT_TYPE_URI: 489 | type = bookmarkService.TYPE_BOOKMARK; 490 | break; 491 | case node.RESULT_TYPE_FOLDER: 492 | type = bookmarkService.TYPE_FOLDER; 493 | break; 494 | case node.RESULT_TYPE_SEPARATOR: 495 | type = bookmarkService.TYPE_SEPARATOR; 496 | break; 497 | case node.RESULT_TYPE_QUERY: 498 | type = bookmarkService.TYPE_BOOKMARK; 499 | break; 500 | } 501 | 502 | return createItem(type, node.itemId, node.bookmarkIndex, parentID, node.title, node.uri, node.time, node.accessCount, node.dateAdded, node.lastModified); 503 | } 504 | 505 | /** 506 | * Get the children folders of a folder. 507 | * @param parentID 508 | * @return {Array} 509 | */ 510 | function getChildrenFolders(parentID) { 511 | let children = []; 512 | let folder; 513 | let node; 514 | 515 | let options = historyService.getNewQueryOptions(); 516 | options.excludeItems = true; 517 | options.excludeQueries = true; 518 | options.queryType = historyService.QUERY_TYPE_BOOKMARKS; 519 | 520 | let query = historyService.getNewQuery(); 521 | query.setFolders([parentID], 1); 522 | 523 | let result = historyService.executeQuery(query, options); 524 | 525 | let rootNode = result.root; 526 | rootNode.containerOpen = true; 527 | 528 | for (let i = 0; i < rootNode.childCount; ++i) { 529 | node = rootNode.getChild(i); 530 | 531 | folder = new Folder(node.itemId, node.bookmarkIndex, parentID, node.title, node.dateAdded, node.lastModified); 532 | 533 | if (!isLivemark(folder.id)) { 534 | children.push({ 535 | id: folder.id, 536 | title: folder.title, 537 | excluded: hasDoNotSortAnnotation(folder.id), 538 | recursivelyExcluded: hasRecursiveAnnotation(folder.id), 539 | }); 540 | } 541 | } 542 | 543 | rootNode.containerOpen = false; 544 | 545 | return children; 546 | } 547 | 548 | /** 549 | * The bookmarks menu folder. 550 | * @type {Folder} 551 | */ 552 | let menuFolder = new Folder(bookmarkService.bookmarksMenuFolder); 553 | 554 | /** 555 | * The bookmarks toolbar folder. 556 | * @type {Folder} 557 | */ 558 | let toolbarFolder = new Folder(bookmarkService.toolbarFolder); 559 | 560 | /** 561 | * The unsorted bookmarks folder. 562 | * @type {Folder} 563 | */ 564 | let unsortedFolder = new Folder(bookmarkService.unfiledBookmarksFolder); 565 | 566 | /** 567 | * Get the root folders. 568 | */ 569 | function getRootFolders() { 570 | let folders = []; 571 | for (let folder of [menuFolder, toolbarFolder, unsortedFolder]) { 572 | folders.push({ 573 | id: folder.id, 574 | excluded: hasDoNotSortAnnotation(folder.id), 575 | recursivelyExcluded: hasRecursiveAnnotation(folder.id), 576 | }); 577 | } 578 | 579 | folders[0].title = _("Bookmarks Menu"); 580 | folders[1].title = _("Bookmarks Toolbar"); 581 | folders[2].title = _("Unsorted Bookmarks"); 582 | 583 | return folders; 584 | } 585 | 586 | exports.Bookmark = Bookmark; 587 | exports.BookmarkManager = BookmarkManager; 588 | exports.Folder = Folder; 589 | exports.getChildrenFolders = getChildrenFolders; 590 | exports.getRootFolders = getRootFolders; 591 | exports.Livemark = Livemark; 592 | exports.menuFolder = menuFolder; 593 | exports.Separator = Separator; 594 | exports.SmartBookmark = SmartBookmark; 595 | exports.toolbarFolder = toolbarFolder; 596 | exports.unsortedFolder = unsortedFolder; 597 | 598 | when(function () { 599 | for (let observer of BookmarkManager.prototype.observers) { 600 | bookmarkService.removeObserver(observer); 601 | } 602 | }); 603 | -------------------------------------------------------------------------------- /test/test-main.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 Boucher, Antoni 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | "use strict"; 19 | 20 | const {MENU, TOOLBAR, UNSORTED} = require("sdk/places/bookmarks"); 21 | const simplePrefs = require("sdk/simple-prefs"); 22 | const prefs = simplePrefs.prefs; 23 | const {menuFolder, toolbarFolder, unsortedFolder} = require("lib/bookmarks"); 24 | const {adjustSortCriteria, createEvents, setPreferenceMinimumMaximum} = require("lib/main"); 25 | const {assertBookmarksArray, createBookmark, createFolder, createLivemark, createSeparator, createSmartBookmark, deleteAllBookmarks, deleteItem, ignore, move, rename, resetPreferences, setVisits, sort} = require("./utils"); 26 | 27 | exports.testAutoSort = function (assert) { 28 | // adjustSortCriteria(); 29 | // createEvents(); 30 | 31 | // deleteAllBookmarks(); 32 | 33 | // let folder = createFolder("Folder", menuFolder); 34 | 35 | // let bookmark1 = createBookmark("Title", "http://title.com/", folder); 36 | // let bookmark2 = createBookmark("Test", "http://test.com/", folder); 37 | // let bookmark3 = createBookmark("Abc", "http://abc.com/", folder); 38 | 39 | // prefs.auto_sort = true; 40 | 41 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark3, bookmark2, bookmark1]); 42 | // assert.strictEqual(folder.getChildren().length, 1); 43 | 44 | // prefs.auto_sort = false; 45 | 46 | // deleteAllBookmarks(); 47 | 48 | // folder = createFolder("Folder", menuFolder); 49 | 50 | // bookmark1 = createBookmark("Title", "http://title.com/", folder); 51 | // bookmark2 = createBookmark("Test", "http://test.com/", folder); 52 | // bookmark3 = createBookmark("Abc", "http://abc.com/", folder); 53 | 54 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2, bookmark3]); 55 | // assert.strictEqual(folder.getChildren().length, 1); 56 | 57 | // resetPreferences(); 58 | }; 59 | 60 | exports.testAutoSortOnChanges = function (assert) { 61 | // adjustSortCriteria(); 62 | // createEvents(); 63 | // prefs.auto_sort = true; 64 | 65 | // deleteAllBookmarks(); 66 | 67 | // // Test adding bookmarks. 68 | // let folder = createFolder("Folder", menuFolder); 69 | 70 | // let bookmark1 = createBookmark("Title21", "http://title21.com/", folder); 71 | 72 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1]); 73 | // assert.strictEqual(folder.getChildren().length, 1); 74 | 75 | // let bookmark2 = createBookmark("Test22", "http://test22.com/", folder); 76 | 77 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark2, bookmark1]); 78 | // assert.strictEqual(folder.getChildren().length, 1); 79 | 80 | // let bookmark3 = createBookmark("Abc23", "http://abc23.com/", folder); 81 | 82 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark3, bookmark2, bookmark1]); 83 | // assert.strictEqual(folder.getChildren().length, 1); 84 | 85 | // // Test changing bookmarks. 86 | // rename(bookmark3, "Zebra23"); 87 | 88 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark2, bookmark1, bookmark3]); 89 | // assert.strictEqual(folder.getChildren().length, 1); 90 | 91 | // rename(bookmark2, "Title Test22"); 92 | 93 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2, bookmark3]); 94 | // assert.strictEqual(folder.getChildren().length, 1); 95 | 96 | // // Test moving bookmarks. 97 | // move(bookmark3, 0); 98 | 99 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2, bookmark3]); 100 | // assert.strictEqual(folder.getChildren().length, 1); 101 | 102 | // move(bookmark1, 4); 103 | 104 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2, bookmark3]); 105 | // assert.strictEqual(folder.getChildren().length, 1); 106 | 107 | // let bookmark4 = createBookmark("Abc24", "http://abc24.com/", menuFolder); 108 | 109 | // move(bookmark4, 4, folder); 110 | 111 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark4, bookmark1, bookmark2, bookmark3]); 112 | // assert.strictEqual(folder.getChildren().length, 1); 113 | 114 | // let separator3 = createSeparator(folder); 115 | // let bookmark10 = createBookmark("Firefox30", "http://firefox30.com/", folder); 116 | 117 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark4, bookmark1, bookmark2, bookmark3]); 118 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark10]); 119 | // assert.strictEqual(folder.getChildren().length, 2); 120 | 121 | // move(separator3, 3); 122 | 123 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark4, bookmark1, bookmark2]); 124 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark10, bookmark3]); 125 | // assert.strictEqual(folder.getChildren().length, 2); 126 | 127 | // move(bookmark4, 2); 128 | 129 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark4, bookmark1, bookmark2]); 130 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark10, bookmark3]); 131 | // assert.strictEqual(folder.getChildren().length, 2); 132 | 133 | // move(bookmark4, 7); 134 | 135 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2]); 136 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark4, bookmark10, bookmark3]); 137 | // assert.strictEqual(folder.getChildren().length, 2); 138 | 139 | // move(bookmark10, 2); 140 | 141 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark10, bookmark1, bookmark2]); 142 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark4, bookmark3]); 143 | // assert.strictEqual(folder.getChildren().length, 2); 144 | 145 | // let separator4 = createSeparator(folder); 146 | // let bookmark11 = createBookmark("Mozilla31", "http://mozilla31.com/", folder); 147 | 148 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark10, bookmark1, bookmark2]); 149 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark4, bookmark3]); 150 | // assertBookmarksArray(assert, folder.getChildren()[2], [bookmark11]); 151 | // assert.strictEqual(folder.getChildren().length, 3); 152 | 153 | // move(bookmark10, 4); 154 | 155 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2]); 156 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark4, bookmark10, bookmark3]); 157 | // assertBookmarksArray(assert, folder.getChildren()[2], [bookmark11]); 158 | // assert.strictEqual(folder.getChildren().length, 3); 159 | 160 | // move(bookmark10, 9); 161 | 162 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2]); 163 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark4, bookmark3]); 164 | // assertBookmarksArray(assert, folder.getChildren()[2], [bookmark10, bookmark11]); 165 | // assert.strictEqual(folder.getChildren().length, 3); 166 | 167 | // move(separator4, 4); 168 | 169 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2]); 170 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark4]); 171 | // assertBookmarksArray(assert, folder.getChildren()[2], [bookmark10, bookmark11, bookmark3]); 172 | // assert.strictEqual(folder.getChildren().length, 3); 173 | 174 | // deleteItem(separator3); 175 | // deleteItem(separator4); 176 | // deleteItem(bookmark10); 177 | // deleteItem(bookmark11); 178 | 179 | // // Test deleting bookmarks. 180 | // let separator1 = createSeparator(folder); 181 | // let bookmark5 = createBookmark("One Test25", "http://one25.com/", folder); 182 | // let bookmark6 = createBookmark("Two tests26", "http://two26.com/", folder); 183 | // let separator2 = createSeparator(folder); 184 | // let bookmark7 = createBookmark("Auie27", "http://auie27.com/", folder); 185 | 186 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark4, bookmark1, bookmark2, bookmark3]); 187 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark5, bookmark6]); 188 | // assertBookmarksArray(assert, folder.getChildren()[2], [bookmark7]); 189 | // assert.strictEqual(folder.getChildren().length, 3); 190 | 191 | // deleteItem(bookmark1); 192 | 193 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark4, bookmark2, bookmark3]); 194 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark5, bookmark6]); 195 | // assertBookmarksArray(assert, folder.getChildren()[2], [bookmark7]); 196 | // assert.strictEqual(folder.getChildren().length, 3); 197 | 198 | // deleteItem(separator2); 199 | 200 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark4, bookmark2, bookmark3]); 201 | // assertBookmarksArray(assert, folder.getChildren()[1], [bookmark7, bookmark5, bookmark6]); 202 | // assert.strictEqual(folder.getChildren().length, 2); 203 | 204 | // deleteItem(separator1); 205 | 206 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark4, bookmark7, bookmark5, bookmark2, bookmark6, bookmark3]); 207 | // assert.strictEqual(folder.getChildren().length, 1); 208 | 209 | // // Test multiple changes. 210 | // let folder2 = createFolder("Folder", toolbarFolder); 211 | // let bookmark8 = createBookmark("Abc28", "http://abc28.com/", folder2); 212 | // let bookmark9 = createBookmark("Test29", "http://test29.com/", folder2); 213 | 214 | // assertBookmarksArray(assert, folder2.getChildren()[0], [bookmark8, bookmark9]); 215 | // assert.strictEqual(folder2.getChildren().length, 1); 216 | 217 | // rename(bookmark3, "Aiue23"); 218 | // rename(bookmark8, "Zeta29"); 219 | 220 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark4, bookmark3, bookmark7, bookmark5, bookmark2, bookmark6]); 221 | // assert.strictEqual(folder.getChildren().length, 1); 222 | 223 | // assertBookmarksArray(assert, folder2.getChildren()[0], [bookmark9, bookmark8]); 224 | // assert.strictEqual(folder2.getChildren().length, 1); 225 | 226 | // rename(bookmark3, "Zebra23"); 227 | 228 | // // Test visiting bookmarks. 229 | // prefs.sort_by = 7; 230 | // prefs.then_sort_by = 0; 231 | 232 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark4, bookmark7, bookmark5, bookmark2, bookmark6, bookmark3]); 233 | // assert.strictEqual(folder.getChildren().length, 1); 234 | 235 | // setVisits(bookmark2, [10]); 236 | // setVisits(bookmark3, [10]); 237 | // setVisits(bookmark4, [100, 200, 300, 400]); 238 | // setVisits(bookmark5, [10]); 239 | // setVisits(bookmark6, [10]); 240 | // setVisits(bookmark7, [10]); 241 | 242 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark7, bookmark5, bookmark2, bookmark6, bookmark3, bookmark4]); 243 | // assert.strictEqual(folder.getChildren().length, 1); 244 | 245 | // resetPreferences(); 246 | }; 247 | 248 | exports.testAutoSortOnOptionChanges = function (assert) { 249 | // adjustSortCriteria(); 250 | // createEvents(); 251 | 252 | // // Sort Menu Folder. 253 | // deleteAllBookmarks(); 254 | 255 | // let folder = createFolder("Folder", menuFolder); 256 | 257 | // let bookmark1 = createBookmark("Title", "http://title.com/", folder); 258 | // let bookmark2 = createBookmark("Test", "http://test.com/", folder); 259 | // let bookmark3 = createBookmark("Abc", "http://abc.com/", folder); 260 | 261 | // ignore(MENU); 262 | // prefs.auto_sort = true; 263 | 264 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2, bookmark3]); 265 | // assert.strictEqual(folder.getChildren().length, 1); 266 | 267 | // sort(MENU); 268 | 269 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark3, bookmark2, bookmark1]); 270 | // assert.strictEqual(folder.getChildren().length, 1); 271 | 272 | // prefs.auto_sort = false; 273 | 274 | // // Sort Toolbar Folder. 275 | // deleteAllBookmarks(); 276 | 277 | // folder = createFolder("Folder", toolbarFolder); 278 | 279 | // bookmark1 = createBookmark("Title", "http://title.com/", folder); 280 | // bookmark2 = createBookmark("Test", "http://test.com/", folder); 281 | // bookmark3 = createBookmark("Abc", "http://abc.com/", folder); 282 | 283 | // ignore(TOOLBAR); 284 | // prefs.auto_sort = true; 285 | 286 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2, bookmark3]); 287 | // assert.strictEqual(folder.getChildren().length, 1); 288 | 289 | // sort(TOOLBAR); 290 | 291 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark3, bookmark2, bookmark1]); 292 | // assert.strictEqual(folder.getChildren().length, 1); 293 | 294 | // prefs.auto_sort = false; 295 | 296 | // // Sort Unsorted Folder. 297 | // deleteAllBookmarks(); 298 | 299 | // folder = createFolder("Folder", unsortedFolder); 300 | 301 | // bookmark1 = createBookmark("Title", "http://title.com/", folder); 302 | // bookmark2 = createBookmark("Test", "http://test.com/", folder); 303 | // bookmark3 = createBookmark("Abc", "http://abc.com/", folder); 304 | 305 | // ignore(UNSORTED); 306 | // prefs.auto_sort = true; 307 | 308 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2, bookmark3]); 309 | // assert.strictEqual(folder.getChildren().length, 1); 310 | 311 | // sort(UNSORTED); 312 | 313 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark3, bookmark2, bookmark1]); 314 | // assert.strictEqual(folder.getChildren().length, 1); 315 | 316 | // prefs.auto_sort = false; 317 | 318 | // // Sort Order. 319 | // deleteAllBookmarks(); 320 | 321 | // folder = createFolder("Folder", menuFolder); 322 | 323 | // let folder1 = createFolder("Folder 1", folder); 324 | // let livemark1 = createLivemark("Livemark", "http://www.mozilla.org/", folder); 325 | // let smartBookmark1 = createSmartBookmark("Smart Bookmark", "MostVisited", "place:sort=8&maxResults=10", folder); 326 | // bookmark1 = createBookmark("Bookmark", "http://title.com/", folder); 327 | 328 | // prefs.folder_sort_order = 1; 329 | // prefs.livemark_sort_order = 2; 330 | // prefs.smart_bookmark_sort_order = 3; 331 | // prefs.bookmark_sort_order = 4; 332 | // prefs.auto_sort = true; 333 | 334 | // assertBookmarksArray(assert, folder.getChildren()[0], [folder1, livemark1, smartBookmark1, bookmark1]); 335 | // assert.strictEqual(folder.getChildren().length, 1); 336 | 337 | // prefs.bookmark_sort_order = 1; 338 | 339 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, folder1, livemark1, smartBookmark1]); 340 | // assert.strictEqual(folder.getChildren().length, 1); 341 | 342 | // prefs.smart_bookmark_sort_order = 1; 343 | 344 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, folder1, smartBookmark1, livemark1]); 345 | // assert.strictEqual(folder.getChildren().length, 1); 346 | 347 | // prefs.folder_sort_order = 4; 348 | 349 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, smartBookmark1, livemark1, folder1]); 350 | // assert.strictEqual(folder.getChildren().length, 1); 351 | 352 | // prefs.livemark_sort_order = 1; 353 | 354 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, livemark1, smartBookmark1, folder1]); 355 | // assert.strictEqual(folder.getChildren().length, 1); 356 | 357 | // prefs.folder_sort_order = 1; 358 | 359 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, folder1, livemark1, smartBookmark1]); 360 | // assert.strictEqual(folder.getChildren().length, 1); 361 | 362 | // // Sort criteria. 363 | // deleteAllBookmarks(); 364 | 365 | // folder = createFolder("Folder", toolbarFolder); 366 | 367 | // bookmark1 = createBookmark("Test", "http://1test.com/", folder); 368 | // bookmark2 = createBookmark("Test", "http://2test.com/", folder); 369 | // bookmark3 = createBookmark("Abc", "http://3abc.com/", folder); 370 | 371 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark3, bookmark1, bookmark2]); 372 | // assert.strictEqual(folder.getChildren().length, 1); 373 | 374 | // prefs.sort_by = 1; 375 | 376 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2, bookmark3]); 377 | // assert.strictEqual(folder.getChildren().length, 1); 378 | 379 | // prefs.sort_by = 0; 380 | // prefs.inverse = true; 381 | // prefs.then_inverse = true; 382 | 383 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2, bookmark3]); 384 | // assert.strictEqual(folder.getChildren().length, 1); 385 | 386 | // prefs.then_sort_by = 1; 387 | 388 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark2, bookmark1, bookmark3]); 389 | // assert.strictEqual(folder.getChildren().length, 1); 390 | 391 | // prefs.inverse = false; 392 | 393 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark3, bookmark2, bookmark1]); 394 | // assert.strictEqual(folder.getChildren().length, 1); 395 | 396 | // prefs.then_inverse = false; 397 | 398 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark3, bookmark1, bookmark2]); 399 | // assert.strictEqual(folder.getChildren().length, 1); 400 | 401 | // resetPreferences(); 402 | }; 403 | 404 | exports.testAutoSortDelay = function (assert) { 405 | // adjustSortCriteria(); 406 | // createEvents(); 407 | 408 | // prefs.delay = 1; 409 | // prefs.folder_delay = 3; 410 | // prefs.auto_sort = true; 411 | 412 | // deleteAllBookmarks(); 413 | 414 | // let folder = createFolder("Folder", menuFolder); 415 | 416 | // let bookmark1 = createBookmark("Title", "http://title.com/", folder); 417 | 418 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1]); 419 | // assert.strictEqual(folder.getChildren().length, 1); 420 | 421 | // let bookmark2 = createBookmark("Test", "http://test.com/", folder); 422 | 423 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark2, bookmark1]); 424 | // assert.strictEqual(folder.getChildren().length, 1); 425 | 426 | // let bookmark3 = createBookmark("Abc", "http://abc.com/", folder); 427 | 428 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark3, bookmark2, bookmark1]); 429 | // assert.strictEqual(folder.getChildren().length, 1); 430 | 431 | // let folder1 = createFolder("Folder1", folder); 432 | 433 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark3, bookmark2, bookmark1, folder1]); 434 | // assert.strictEqual(folder.getChildren().length, 1); 435 | 436 | // assertBookmarksArray(assert, folder.getChildren()[0], [folder1, bookmark3, bookmark2, bookmark1]); 437 | // assert.strictEqual(folder.getChildren().length, 1); 438 | 439 | // prefs.auto_sort = false; 440 | // prefs.delay = 0; 441 | // prefs.folder_delay = 30; 442 | 443 | // deleteAllBookmarks(); 444 | 445 | // folder = createFolder("Folder", menuFolder); 446 | 447 | // bookmark1 = createBookmark("Title", "http://title.com/", folder); 448 | // bookmark2 = createBookmark("Test", "http://test.com/", folder); 449 | // bookmark3 = createBookmark("Abc", "http://abc.com/", folder); 450 | 451 | // assertBookmarksArray(assert, folder.getChildren()[0], [bookmark1, bookmark2, bookmark3]); 452 | // assert.strictEqual(folder.getChildren().length, 1); 453 | 454 | // resetPreferences(); 455 | }; 456 | 457 | exports.testPreferenceMaximumMinimum = function (assert) { 458 | setPreferenceMinimumMaximum(); 459 | 460 | prefs.folder_sort_order = 0; 461 | assert.strictEqual(prefs.folder_sort_order, 1); 462 | 463 | prefs.folder_sort_order = 5; 464 | assert.strictEqual(prefs.folder_sort_order, 4); 465 | 466 | prefs.livemark_sort_order = 0; 467 | assert.strictEqual(prefs.livemark_sort_order, 1); 468 | 469 | prefs.livemark_sort_order = 5; 470 | assert.strictEqual(prefs.livemark_sort_order, 4); 471 | 472 | prefs.smart_bookmark_sort_order = 0; 473 | assert.strictEqual(prefs.smart_bookmark_sort_order, 1); 474 | 475 | prefs.smart_bookmark_sort_order = 5; 476 | assert.strictEqual(prefs.smart_bookmark_sort_order, 4); 477 | 478 | prefs.bookmark_sort_order = 0; 479 | assert.strictEqual(prefs.bookmark_sort_order, 1); 480 | 481 | prefs.bookmark_sort_order = 5; 482 | assert.strictEqual(prefs.bookmark_sort_order, 4); 483 | 484 | prefs.folder_delay = 2; 485 | assert.strictEqual(prefs.folder_delay, 3); 486 | 487 | resetPreferences(); 488 | }; 489 | 490 | require("sdk/test").run(exports); 491 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------