Полезная информация

Юристы зарабатывают огромные деньги и славу, оперируя хорошим знанием законов. Правила форума — простой путь к успешному общению.

№17176Сегодня 16:18:01

Dumby
Участник
 
Группа: Members
Зарегистрирован: 12-08-2012
Сообщений: 2251
UA: Firefox 78.0

Re: Custom Buttons

Garalf пишет

Посмотри пожалуйста...

Сейчас времени нет, однако, чуть прикоснулся

скрытый текст

Выделить код

Код:

(obj => {
	this._handleClick = () => obj.popup.openPopup(this, "after_start");
	this.onmouseenter = e => this.tooltipText = this.label +
		"\nЛ: Меню кнопки\nП: CB меню\n\nПапка для экспорта:\n" + (obj.path || "Не установлено.");
	addDestructor(reason => reason == "delete" && Services.prefs.clearUserPref(obj.pref));
})({
	get popup() {
		var popup = document.createXULElement("menupopup");
		addEventListener("command", e => this[e.target.value](), false, popup);
		var keys = ["label", "value", "image"];
		for(var data of [
			["Экспорт закладок в HTML-файл", "export", "data:image/x-icon;base64,AAABAAEAEhIAAAEAIACABQAAFgAAACgAAAASAAAAJAAAAAEAIAAAAAAAWAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////8AAAAAAAAAAAAAAAAAAAAADg/o/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////8AAAAAAAAAAAAAAAAAAAAADg/o/w4P6P8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////8AAAAAAAAAAAAAAAAAAAAADg/o/zUq6P8OD+j/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////8AAAAAAAAAAAAAAAAAAAAADg/o/0RC//0cE+X/Dg/o/wAAAAAAAAAAAAAAAAAAAAAAAAAA/////xQW5/8tMOT/Njfw/0BA+v9JSP//UU///1hT//9aVv3/RUL5/zQy+f8zNPH/JSHa/w4P6P8AA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//8AAg9/AAIPPwACDx8AAg8PAAIABwACAAMAAgAHAAIADwACAA8AAgAHAAIAAwACAAcAAg8PAAIPHwACDz8AAg9/AAP//wAA="],
			["Импорт закладок из HTML-файла", "import", "data:image/x-icon;base64,AAABAAEAEhIAAAEAIACABQAAFgAAACgAAAASAAAAJAAAAAEAIAAAAAAAWAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////8AAAAADg/o/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////8OD+j/Dg/o/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////////////////////w4P6P81Kuj/Dg/o/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////////////////Dg/o/xwT5f9EQv/9Dg/o/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////8OD+j/JSHa/zM08f80Mvn/RUL5/1pW/f9YU///UU///0lI//9AQPr/Njfw/y0w5P8UFuf/AAAAAAAAAAAAAAAA/////w4P6P8cHcr/NDbb/Tw94v85TtP9F5sr/zk0+f9CPv/9PDn+/zQx/f0qKPj/Hh7v/RQV4v8QEeb9AAAAAAAAAAAAAAAA//////////8OD+j/Hx/D/yVDqf8Xmyv/F5sr/zk0+f85NPn/MjD1/ysq9f8kJPX/Hh7x/xcY6f8OD+j/AAAAAAAAAAAAAAAA////////////////Dg/o/xebK/838l/9F5sr/w4P6P8OD+j/Dg/o/w4P6P8OD+j/Dg/o/w4P6P8OD+j/AAAAAAAAAAAAAAAA////////////////F5sr/x/tRf88/17/QuJf/23Yfv+s/Lj/qPyz/6T8rv+g+ar/m/Sk/5bwn/99xID/AAAAAAAAAAAAAAAA//////////8Xmyv/Kt1J/znvVf85+Vn/Qf9j/0r/a/9E/2j/Qf9k/zv9Xf8y91P/KexI/x/kPf8DkBT/AAAAAAAAAAAAAAAA/////xebK/8axzf/MtZL/TrhU/9B71z9Rvpk/0f+Z/9F/Wf9Pv9h/zX+WP0p+k7/IvNE/RjpOP8HlBn9AAAAAAAAAAAAAAAA//////////8Xmyv/FMIy/zHWSP844FH/CZgc/wmYHP8JmBz/CZgc/wmYHP8JmBz/CZgc/wmYHP8JmBz/AAAAAAAAAAAAAAAA////////////////F5sr/w28LP8w10j9KL08/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/////////////////////xebK/8UvS7/HKsv/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////8Xmyv/F5sr/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//////////////////////////8AAAAAF5sr/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//8AAgv/AAID/wACA/8AAgP/AAIAAwACAAMAAgADAAIAAwACAAMAAgADAAIAAwACAAMAAgP/AAID/wACA/8AAgv/AAP//wAA="],
			,
			["Открыть папку для экспорта закладок", "reveal", "data:image/x-icon;base64,AAABAAEAEhIAAAEAIACABQAAFgAAACgAAAASAAAAJAAAAAEAIAAAAAAAWAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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0//Ly8v77+/v/tra2xQAAABIAAAAl19fX4fr6+v/39/f99/f3//f39/339/f99/f3/v7+/v//////7Ozs6OPj4+Xl5eXo6+vr6v///+/s7OzfJCQkRBEREQMAAAAT0tLS0P///////////////////////////////7y8vL0JCQktCgoKCQ4ODgcMDAwHERERCBMTEwkREREEMzMzAQAAAAAPDw8EGxsbOcTExL3Pz8/Ozs7Oz9DQ0NPFxcXCYGBgbgAAAAkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALi4uAR0dHQEREREEEhISBRAQEAMaGhoCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//8AAgABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAB/wACB/8AA///AAP//wAA="],
			["Экспорт закладок в HTML без запроса", "silentExport", "data:image/x-icon;base64,AAABAAEAEhIAAAEAIACABQAAFgAAACgAAAASAAAAJAAAAAEAIAAAAAAAWAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAgAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAHAAAAAwAAAAAAAAANAAAAMwAAAEsAAABOAAAATgAAAE4AAABOAAAATgAAAE4AAABOAAAATgAAAE4AAABOAAAATgAAAE8AA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b//////////gAAAC0FBQUGDQ0NBA4ODgQNDQ0EDQ0NBA0NDQQNDQ0EDQ0NBA0NDQQaGhoCAAAAAAAAAAAAAAAAFxcXARkZGQs3NzcwISEhHSkpKQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//8AAgABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAwACD/8AA///AAP//wAA="]
		])
			if (data) {
				var menuitem = popup.appendChild(document.createXULElement("menuitem"));
				menuitem.className = "menuitem-iconic";
				keys.forEach((key, ind) => menuitem.setAttribute(key, data[ind]));
			} else
				popup.append(document.createXULElement("menuseparator"));

		ChromeUtils.defineESModuleGetters(this, {
			BookmarkHTMLUtils: "resource://gre/modules/BookmarkHTMLUtils.sys.mjs"
		});
		delete this.popup;
		return this.popup = self.appendChild(popup);
	},
	pref: "CB.exportsBookmarksToHTMLFile.path",
	get path() {
		return Services.prefs.getStringPref(this.pref, null);
	},
	pick(title, modeOpen) {
		var fp = makeFilePicker();
		fp.init(window.browsingContext, title, modeOpen ? fp.modeOpen : fp.modeGetFolder);
		modeOpen && fp.appendFilters(fp.filterHTML);
		var {path} = this;
		if (path) fp.displayDirectory = FileUtils.File(path);
		return new Promise(resolve => fp.open(
			res => resolve(res == fp.returnOK && fp.file)
		));
	},
	async import() {
		var file = await this.pick("Выберите HTML-файл для импорта закладок", true);
		file && this.BookmarkHTMLUtils.importFromFile(file.path).then(null, alert);
	},
	async export(justSetPath) {
		var dir = await this.pick("Укажите папку для экспорта закладок!");
		if (!dir) return;
		dir.path != this.path && Services.prefs.setStringPref(this.pref, dir.path);
		justSetPath || this.silentExport(dir);
	},
	silentExport(dir) {
		if (!dir && !(dir = this.checkPath(this.path))) return;
		dir.append("bookmarks-" + new Date().toLocaleDateString("mn") + ".html");
		this.BookmarkHTMLUtils.exportToFile(dir.path)
			.then(() => this.notify(dir.path), alert);
	},
	ns: "Папка для экспорта не установлена.\n\nУстановить папку?",
	nf: path => `Папка для экспорта не найдена.\n${path}\n\nВыбрать другую?`,
	checkPath(path, justSetPath) {
		if (!path)
			return void(confirm(this.ns) && this.export(justSetPath));
		var dir = FileUtils.File(path);
		if (dir.exists() && dir.isDirectory()) return dir;
		confirm(this.nf(path)) && this.export(justSetPath);
	},
	reveal() {
		var dir = this.checkPath(this.path, true);
		dir && dir.reveal();
	},
	get notify() {
		var as = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
		var func = path => setTimeout(as.closeAlert, 3500, as.showAlertNotification(
			self.image, self.label, "Экспортировал закладки как HTML в " + path
		));
		delete this.notify; return this.notify = func;
	}
});

Отсутствует

 

№17177Сегодня 18:33:13

Garalf
Участник
 
Группа: Members
Зарегистрирован: 19-09-2017
Сообщений: 320
UA: Firefox 132.0

Re: Custom Buttons

Dumby
Спасибо. Все работает.

На форуме

 

Board footer

Powered by PunBB
Modified by Mozilla Russia
Copyright © 2004–2020 Mozilla Russia GitHub mark
Язык отображения форума: [Русский] [English]