Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name prohardver.hu : forum : hotkeys in forum
- // @include http://prohardver.hu/*
- // @include http://mobilarena.hu/*
- // @include http://logout.hu/*
- // @include http://itcafe.hu/*
- // @include http://gamepod.hu/*
- // @include http://hardverapro.hu/*
- // @version 1.1
- // ==/UserScript==
- (function()
- {
- var event_handler = function()
- {
- var is_old_style = document.location.host == "logout.hu" || document.location.host == "hardverapro.hu";
- var is_in_article = function()
- {
- var path = document.location.pathname;
- return path.substr(0, 6) == "/teszt" || path.substr(0, 5) == "/cikk" || path.substr(0, 4) == "/hir";
- }
- var is_in_list = function()
- {
- var path = document.location.pathname.substr(0, 7);
- return path == "/temak/" || path == "/aprok/";
- }
- var get_block_size = function()
- {
- try
- {
- if (is_old_style)
- {
- var text = document.evaluate("//select[@name=\"listsett\"]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.options[0].text;
- var n = text.indexOf(" ");
- if (n == -1)
- return null;
- return text.substr(0, n) * 1;
- }
- else
- {
- return document.evaluate("//div[@id=\"navi_top_prefs\"]/div[1]/a/b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerText * 1;
- }
- }
- catch (e)
- {
- return null;
- }
- }
- var get_article_pages = function(id, path)
- {
- var obj = document.getElementById(id);
- if (obj == null)
- return null;
- return document.evaluate(path, obj, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
- }
- var go_to_forum = function(in_new_window)
- {
- if (typeof in_new_window == "boolean" && in_new_window)
- window.open("/forum/index.html");
- else if (document.location.pathname != "/forum/index.html")
- document.location.href = "/forum/index.html";
- };
- var go_to_forum_in_new_window = function()
- {
- go_to_forum(true);
- }
- var go_to_private_messages = function(in_new_window)
- {
- if (typeof in_new_window == "boolean" && in_new_window)
- window.open("/privatok/listaz.php");
- else if (document.location.pathname != "/privatok/listaz.php")
- document.location.href = "/privatok/listaz.php";
- };
- var go_to_private_messages_in_new_window = function()
- {
- go_to_private_messages(true);
- }
- var go_to_article_page = function(target)
- {
- if (is_old_style)
- {
- try
- {
- var pages = document.evaluate("//div[@class=\"toc\"]/form/select", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.options;
- var count = pages.length;
- var index = null;
- if (target == "first" && count > 0)
- {
- index = 0;
- }
- else if (target == "last" && count > 0)
- {
- index = count - 1;
- }
- else
- {
- var current = pages.selectedIndex;
- if (target == "next" && current < count - 1)
- index = current + 1;
- else if (target == "prev" && current > 0)
- index = current - 1;
- }
- if (index == null)
- return;
- var path = document.location.pathname;
- path = path.substr(0, path.lastIndexOf("/") + 1) + pages[index].value + ".html";
- if (path != document.location.pathname)
- document.location.pathname = path;
- }
- catch (e)
- {
- }
- }
- else
- {
- var pages = get_article_pages("toc1", "div[1]/ul/li/a");
- if (pages == null)
- pages = get_article_pages("navi_top_pages", "div[1]/div[1]/ul/li/a");
- if (pages == null)
- return;
- var count = pages.snapshotLength;
- var index = null;
- if (target == "first" && count > 0)
- {
- index = 0;
- }
- else if (target == "last" && count > 0)
- {
- index = count - 1;
- }
- else
- {
- var current = null;
- var href = window.location.href;
- for (var n = 0; n < count; n++)
- {
- if (pages.snapshotItem(n).href == href)
- {
- current = n;
- break;
- }
- }
- if (current != null)
- {
- if (target == "next" && current < count - 1)
- index = current + 1;
- else if (target == "prev" && current > 0)
- index = current - 1;
- }
- }
- if (index != null)
- {
- href = pages.snapshotItem(index).href;
- if (href != document.location.href)
- document.location.href = href;
- }
- }
- }
- var go_to_prev_page = function ()
- {
- if (is_in_article())
- {
- go_to_article_page("prev");
- return;
- }
- var prev = document.evaluate(is_old_style ? "//img[@src=\"/design/arr_prev.gif\"]" : "//img[@src=\"/design/arr-prev-norm.gif\"]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
- if (prev)
- document.location.href = prev.parentNode.href;
- };
- var go_to_next_page = function ()
- {
- if (is_in_article())
- {
- go_to_article_page("next");
- return;
- }
- var next = document.evaluate(is_old_style ? "//img[@src=\"/design/arr_next.gif\"]" : "//img[@src=\"/design/arr-next-norm.gif\"]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
- if (next)
- document.location.href = next.parentNode.href;
- };
- var go_to_first_page = function()
- {
- if (is_in_article())
- {
- go_to_article_page("first");
- return;
- }
- var path = document.location.pathname;
- var search = document.location.search;
- if (is_in_list())
- {
- path = path.substr(0, path.lastIndexOf("/")) + "/listaz.php";
- search = "";
- }
- else
- {
- var block_size = get_block_size();
- if (block_size == null)
- return;
- path = path.substr(0, path.lastIndexOf("/")) + "/hsz_1-" + block_size + ".html";
- }
- if (path != document.location.pathname)
- document.location.pathname = path;
- else if (search != document.location.search)
- document.location.search = search;
- };
- var go_to_last_page = function()
- {
- if (is_in_article())
- {
- go_to_article_page("last");
- return;
- }
- var path = document.location.pathname;
- var block_size = get_block_size();
- var last;
- try
- {
- if (is_old_style)
- {
- last = document.evaluate("//select[@name=\"ugro\"]/option[last()]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.text;
- var n = last.lastIndexOf(" ");
- if (n == -1)
- return;
- last = last.substr(n + 1) * 1;
- }
- else
- {
- last = document.evaluate("//div[@id=\"navi_top_pages\"]/div[1]/div[1]/ul/li[last()]/a/span[2]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerText * 1;
- }
- }
- catch (e)
- {
- return;
- }
- if (last == null || block_size == null)
- return;
- last -= (last % block_size);
- if (is_in_list())
- path = path.substr(0, path.lastIndexOf("/")) + "/listaz.php?offset=" + last;
- else
- path = path.substr(0, path.lastIndexOf("/")) + "/hsz_" + (last + 1) + "-" + (last + block_size) + ".html";
- if (path != document.location.pathname)
- document.location.pathname = path;
- };
- var go_to_comments = function()
- {
- try
- {
- document.location.href = document.evaluate(is_old_style ? "//a[@name=\"rel_msgs\"]" : "//li[@class=\"oforum\"]/a", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.href;
- }
- catch (e)
- {
- }
- };
- var go_to_article = function()
- {
- try
- {
- document.location.href = document.evaluate(is_old_style ? "//div[@class=\"kapcsanyag\"]/a" : "//div[@class=\"inr\"]/following-sibling::a", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.href;
- }
- catch (e)
- {
- }
- };
- var hotkeys =
- {
- "ctrl-alt-f": go_to_forum,
- "ctrl-shift-f": go_to_forum_in_new_window,
- "ctrl-alt-p": go_to_private_messages,
- "ctrl-shift-p": go_to_private_messages_in_new_window,
- "ctrl-alt-2": go_to_prev_page,
- "ctrl-alt-3": go_to_next_page,
- "ctrl-alt-1": go_to_first_page,
- "ctrl-alt-4": go_to_last_page,
- "ctrl-alt-c": go_to_comments,
- "ctrl-alt-a": go_to_article
- };
- keylib_initialize(window, hotkeys);
- }
- if (document.body)
- event_handler();
- else
- window.addEventListener("load", event_handler, false);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement