Skip to content

Instantly share code, notes, and snippets.

@webframp
Created June 22, 2016 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webframp/f91aa73bc51c5e43e71b9da3ef226900 to your computer and use it in GitHub Desktop.
Save webframp/f91aa73bc51c5e43e71b9da3ef226900 to your computer and use it in GitHub Desktop.
// -*- mode: javascript -*-
/// SETTINGS
url_remoting_fn = load_url_in_new_buffer;
url_completion_use_history = true;
var click_in_new_buffer_target = OPEN_NEW_BUFFER_BACKGROUND;
// let xkcd-mode put the funny alt text into the page.
xkcd_add_title = true;
// user prefs
session_pref("network.automatic-ntlm-auth.allow-non-fqdn", true);
session_pref("network.negotiate-auth.allow-non-fqdn", true);
session_pref("layout.spellcheckDefault", 2);
// Autostart MOZREPL
user_pref('extensions.mozrepl.autoStart', true);
// let (mozrepl_init = get_home_directory()) {
// mozrepl_init.appendRelativePath(".mozrepl-conkeror.js");
// session_pref('extensions.mozrepl.initUrl', make_uri(mozrepl_init).spec);
// };
var mozrepl_init = get_home_directory();
mozrepl_init.appendRelativePath(".mozrepl-conkeror.js");
session_pref('extensions.mozrepl.initUrl', make_uri(mozrepl_init).spec);
// let (mozrepl_init = get_home_directory()) {
// mozrepl_init.appendRelativePath();
// session_pref('extensions.mozrepl.initUrl', make_uri(mozrepl_init).spec);
// }
// Permission Manager
// http://stackoverflow.com/questions/33536342/how-to-configure-desktop-notification-in-conkeror-browser
// https://truongtx.me/2016/02/18/conkeror-working-with-web-page-permission
// https://github.com/tmtxt/conkerorrc
const permissionManager = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager);
var permissionList = [
{desc: "Audio Capture", value: "audio-capture"},
{desc: "Video Capture", value: "video-capture"},
{desc: "Geo Location", value: "collocation"},
{desc: "Desktop Notifications", value: "desktop-notification"}
];
var readPermission = function(I) {
return I.minibuffer.read(
$prompt = "Select permission:",
$completer = new all_word_completer(
$completions = permissionList,
$get_string = function(x) {return x.value;},
$get_description = function(x) {return x.desc;}
)
);
};
var addPermission = function(I) {
var perm = yield readPermission(I);
var uri = make_uri(I.buffer.current_uri.prePath);
var allow = Components.interfaces.nsIPermissionManager.ALLOW_ACTION;
permissionManager.add(uri, perm, allow);
I.minibuffer.message("Permission " + perm + " added");
};
var removePermission = function(I) {
var perm = yield readPermission(I);
var uri = make_uri(I.buffer.current_uri.prePath);
var deny = Components.interfaces.nsIPermissionManager.DENY_ACTION;
permissionManager.add(uri, perm, allow);
I.minibuffer.message("Permission " + perm + " removed");
};
interactive("add-permission", "Add specific permission for current uri", addPermission);
interactive("remove-permission", "Remove specific permission for current uri", removePermission);
/// Content Types
// automatically handle some mime types internally.
content_handlers.set("application/pdf", content_handler_save);
/// HOOKS
function update_save_path (info) {
cwd = info.target_file.parent;
}
add_hook("download_added_hook", update_save_path);
// modeline
remove_hook("mode_line_hook", mode_line_adder(clock_widget));
add_hook("mode_line_hook", mode_line_adder(buffer_icon_widget), true);
add_hook("mode_line_hook", mode_line_adder(loading_count_widget), true);
add_hook("mode_line_hook", mode_line_adder(buffer_count_widget), true);
add_hook("mode_line_hook", mode_line_adder(zoom_widget));
// add_hook("mode_line_hook", mode_line_adder(downloads_status_widget)); // BROKEN
/// HINTS
hint_background_color = 'white';
active_hint_background_color = '#00ccff';
register_user_stylesheet(
"data:text/css," +
escape(
"@namespace url(\"http://www.w3.org/1999/xhtml\");\n" +
"span.__conkeror_hint {\n"+
" font-size: 12px !important;\n"+
" line-height: 12px !important;\n"+
"}"));
register_user_stylesheet(
"data:text/css," +
escape (
"span.__conkeror_hint {" +
" border: 1px solid #dddddd !important;" +
" color: white !important;" +
" background-color: black !important;" +
"}"));
require("casual-spelling");
/// SESSION SAVE
require("session");
session_auto_save_auto_load = true;
session_save_buffer_access_order = true;
/// CUSTOMIZATION
// undo close
define_key(default_global_keymap, "C-T", "revive-buffer");
var kill_buffer_original = kill_buffer_original || kill_buffer;
var killed_buffer_urls = [];
var killed_buffer_histories = [];
// remember_killed_buffer
kill_buffer = function (buffer, force) {
var hist = buffer.web_navigation.sessionHistory;
if (buffer.display_uri_string && hist) {
killed_buffer_histories.push(hist);
killed_buffer_urls.push(buffer.display_uri_string);
}
kill_buffer_original(buffer,force);
};
interactive("revive-buffer",
"Loads url from a previously killed buffer",
function restore_killed_buffer (I) {
if (killed_buffer_urls.length !== 0) {
var url = yield I.minibuffer.read(
$prompt = "Restore killed url:",
$completer = new all_word_completer($completions = killed_buffer_urls),
$default_completion = killed_buffer_urls[killed_buffer_urls.length - 1],
$auto_complete = "url",
$auto_complete_initial = true,
$auto_complete_delay = 0,
$require_match = true);
var window = I.window;
var creator = buffer_creator(content_buffer);
var idx = killed_buffer_urls.indexOf(url);
// Create the buffer
var buf = creator(window, null);
// Recover the history
buf.web_navigation.sessionHistory = killed_buffer_histories[idx];
// This line may seem redundant, but it's necessary.
var original_index = buf.web_navigation.sessionHistory.index;
buf.web_navigation.gotoIndex(original_index);
// Focus the new tab
window.buffers.current = buf;
// Remove revived from cemitery
killed_buffer_urls.splice(idx,1);
killed_buffer_histories.splice(idx,1);
} else {
I.window.minibuffer.message("No killed buffer urls");
}
});
@webframp
Copy link
Author

console log:

JavaScript strict warning: chrome://mozrepl/content/repl.js, line 770: SyntaxError: octal literals and octal escape sequences are deprecated
JavaScript strict warning: chrome://mozrepl/content/repl.js, line 770: SyntaxError: octal literals and octal escape sequences are deprecated
JavaScript strict warning: chrome://mozrepl/content/repl.js, line 770: SyntaxError: octal literals and octal escape sequences are deprecated
I, MOZREPL : Listening : 127.0.0.1:4242
JavaScript warning: chrome://conkeror/content/coroutine.js, line 354: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
i: loaded rc file .conkerorrc
JavaScript strict warning: resource://gre/modules/TelemetryEnvironment.jsm, line 492: ReferenceError: reference to undefined property this._environment._currentEnvironment.addons
Console error: [JavaScript Warning: "ReferenceError: reference to undefined property this._environment._currentEnvironment.addons" {file: "resource://gre/modules/TelemetryEnvironment.jsm" line: 492}]
  Category: chrome javascript
Session file not found: C:\Users\SESCRIVA\AppData\Roaming\conkeror.mozdev.org\conkeror\Profiles\euj70xo9.default\sessions\auto-save

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment