-
-
Save havremunken/206bfd4baadc61b1d2b071f12a18f175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name RBKweb Forum Suite | |
// @namespace http://troillprat.no/ | |
// @version 0.1 | |
// @description Gjør RBKweb-forumet sinnsykt mye mer effektivt å bruke | |
// @author Rune Jacobsen <havremunken@gmail.com> | |
// @match http*://www.rbkweb.no/forum/* | |
// @match http*://rbkweb.no/forum/* | |
// @grant none | |
// @require http://code.jquery.com/jquery-latest.js | |
// @require https://raw.githubusercontent.com/azoff/AutoResize/master/jquery.autoresize.min.js | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
var contexts;!function(t,e){var n=t.createElement("style");if(t.getElementsByTagName("head")[0].appendChild(n),n.styleSheet)n.styleSheet.disabled||(n.styleSheet.cssText=e);else try{n.innerHTML=e}catch(t){n.innerText=e}}(document,".frsModal{background-color:#000;opacity:75%;border-radius:20px}.rfsSelectedPost{border:2px solid #000;background-color:#DDE7C7}.rfsUnreadItem td{background-color:#90ee90}.rfsSelectedItem td{background-color:#DDE7C7}.rfsUnreadItem.rfsSelectedItem td{background-color:#EDEEC9}.rfsSelectedItem span.postbody a.rfsSelectedLink{font-weight:900}"),(contexts=contexts||[]).push({contextName:"forumlist",allItems:null,itemsFilter:"",supportsItems:!0,isCurrentContext:function(){return window.location.href.match(/rbkweb\.no\/forum\/index\.php/)},itemSelector:function(){return $("table.forumline:first > tbody > tr").has("td.row1")},unreadSelector:function(){return'td.row1 img[alt="New posts"]'},arrive:function(){forumMap.updateMap(this.getAllItems(),this.getTopUrl())},markItems:function(){this.itemSelector().addClass("rfsItem").has(this.unreadSelector()).addClass("rfsUnreadItem")},getItemStateClass:function(t,e){return console.error("Deprecated!"),t&&e?"rfsSelectedAndUnreadItem":t?"rfsUnreadItem":e?"rfsSelectedItem":""},getItemUrl:function(t){return $("span.forumlink a.forumlink",t.element).first().attr("href")},getAllItems:function(){return null==this.allItems&&(this.allItems=this.createItemsList()),this.allItems},getFilteredItems:function(){var t=new RegExp(this.itemsFilter,"i");return this.getAllItems().filter(e=>e.text.match(t))},createItemsList:function(){var t=[],e=this;return this.itemSelector().each(function(){t.push({element:this,text:e.getItemText(this),unread:e.getUnreadStatus(this),date:e.getDate(this),url:e.getUrl(this)})}),t},handleHotkey:function(t){},getItemText:function(t){return $("td:nth-child(2) span",t).text().replace(/\s{1,100}/," ").trim()},getUnreadStatus:function(t){return $(t).hasClass("rfsUnreadItem")},getDate:function(t){var e=$("td",t).eq(4).text().match(/(\d{2})\.(\d{2}).(\d{4}) (\d{2}):(\d{2})/);return new Date(e[3],e[2]-1,e[1],e[4],e[5])},getUrl:function(t){return $("td span.forumlink a",t).attr("href")},getTopUrl:function(){return $("body > table:nth-child(3) > tbody > tr:nth-child(2) > td:nth-child(4) > table > tbody > tr > td > font > p:nth-child(3) > table:nth-child(2) > tbody > tr > td:nth-child(1) > span.nav > a").attr("href")}}),(contexts=contexts||[]).push({contextName:"posting-topicreview",allItems:null,itemsFilter:"",supportsItems:!0,isCurrentContext:function(){return window.location.href.match(/rbkweb\.no\/forum\/posting\.php\?mode=topicreview/)},itemSelector:function(){return $("table.forumline > tbody > tr").has("td > span.postbody")},createItemsList:function(){var t=[],e=this;return this.itemSelector().each(function(){t.push({element:this,text:e.getItemText(this),unread:e.getUnreadStatus(this),date:e.getDate(this)})}),t},getItemText:function(t){return $("td > table > tbody > tr > td > span.postbody",t).text().replace(/\s{1,100}/," ").trim()},getUnreadStatus:function(t){return $('td img[alt="New posts"]',t).length>0},getDate:function(t){var e=$("td > table > tbody > tr > td > span.postdetails",t).text().match(/Posted: (\d{2})\.(\d{2}).(\d{4}) (\d{2}):(\d{2})/);return new Date(e[3],e[2]-1,e[1],e[4],e[5])},getAuthor:function(t){return $("td span.name b",t).text()},getAllItems:function(){return null==this.allItems&&(this.allItems=this.createItemsList()),this.allItems},getFilteredItems:function(){var t=new RegExp(this.itemsFilter,"i");return this.getAllItems().filter(e=>e.text.match(t))},selectInitialElement:function(){var t=localStorage.getItem("rfsReplyObject");if(t){localStorage.removeItem("rfsReplyObject");var e,n=this,r=JSON.parse(t);if(r.date=new Date(r.date),$.each(this.getAllItems(),function(t,i){dateCompareToMinute(i.date,r.date)&&n.getAuthor(i.element)==r.author&&n.getItemText(i.element).substring(0,10)==r.text.substring(0,10)&&(e=i)}),e)return e}return this.getAllItems()[0]}}),(contexts=contexts||[]).push({contextName:"posting",supportsItems:!1,isCurrentContext:function(){return window.location.href.match(/rbkweb\.no\/forum\/posting\.php\?mode=(newtopic|reply|quote|editpost)/)},goUpSelector:function(){return $("body>table>tbody>tr>td>table>tbody>tr>td>font>p>table>tbody>tr>td:nth-child(2)>span.nav>a.nav:nth-child(2)").first().attr("href")},arrive:function(){$("textarea.post").autoResize(),window.location.href.match(/rbkweb\.no\/forum\/posting\.php\?mode=newtopic/)?$("span.gen > input.post").focus():$("textarea.post").focus()},getFilteredItems:function(){return{element:$("table.forumline tr:nth-child(3)")[0],text:"",unread:!1,date:new Date}},handleHotkey:function(t){13==t.which&&t.ctrlKey&&$('input[name="post"]').trigger("click")}}),(contexts=contexts||[]).push({contextName:"threadlist",supportsItems:!0,itemsFilter:"",isCurrentContext:function(){return window.location.href.match(/rbkweb\.no\/forum\/viewforum\.php\?f=\d*/)},itemSelector:function(){return $("table.forumline tbody tr").has("td.row3Right")},unreadSelector:function(){return'td img[alt="New posts"]'},arrive:function(){},markItems:function(){this.itemSelector().addClass("rfsItem").has(this.unreadSelector()).addClass("rfsUnreadItem")},getItemStateClass:function(t,e){return t&&e?"rfsSelectedAndUnreadItem":t?"rfsUnreadItem":e?"rfsSelectedItem":""},getParentUrl:function(){return $("form > table > tbody > tr:nth-child(2) > td:nth-child(2) > span.nav > a.nav").first().attr("href")},goToSelectedItem:function(){localStorage.setItem("rfsLastEnterThreadSource",window.location.href),$("tr.rfsSelectedItem td > span.gensmall > a").length>0?window.location.href=$("tr.rfsSelectedItem td.row1 > span.gensmall > a").last().attr("href"):window.location.href=$("tr.rfsSelectedItem td.row1 > span.topictitle > a").first().attr("href")},getItemUrl:function(t){return $("td > span.gensmall > a",t.element).length>0?$("td.row1 > span.gensmall > a",t.element).last().attr("href"):$("td.row1 > span.topictitle > a",t.element).first().attr("href")},getAllItems:function(){return null==this.allItems&&(this.allItems=this.createItemsList()),this.allItems},getFilteredItems:function(){var t=new RegExp(this.itemsFilter,"i");return this.getAllItems().filter(e=>e.text.match(t))},createItemsList:function(){var t=[],e=this;return this.itemSelector().each(function(){t.push({element:this,text:e.getItemText(this),unread:e.getUnreadStatus(this),date:e.getDate(this)})}),t},getItemText:function(t){return $("td:nth-child(2) span",t).text().replace(/\s{1,100}/," ").trim()},getUnreadStatus:function(t){return $('td img[alt="New posts"]',t).length>0},getDate:function(t){var e=$("td.row3Right > span.postdetails",t).text().match(/(\d{2})\.(\d{2}).(\d{4}) (\d{2}):(\d{2})/);return new Date(e[3],e[2]-1,e[1],e[4],e[5])},handleHotkey:function(t){if("n"==t.key&&(window.location.href=$('a img[alt="Post new topic"]').parent().attr("href")),188==t.which&&t.shiftKey){var e=$('a:contains("Previous")').first();e.length>0&&(window.location.href=e.attr("href"))}if(190==t.which&&t.shiftKey){var n=$('a:contains("Next")').first();n.length>0&&(window.location.href=n.attr("href"))}}}),(contexts=contexts||[]).push({contextName:"topic",supportsItems:!0,currentlySelectedItem:null,selectedItemLinks:[],currentlySelectedItemSelectedLink:-1,isCurrentContext:function(){return window.location.href.match(/rbkweb\.no\/forum\/viewtopic\.php\?[tp]=\d*/)},goUp:function(){var t=localStorage.getItem("rfsLastEnterThreadSource");t&&t.length>0?(localStorage.removeItem("rfsLastEnterThreadSource"),window.location.href=t):window.location.href=this.goUpSelector()},goUpSelector:function(){return $("body>table>tbody>tr>td>table>tbody>tr>td>font>p>table>tbody>tr>td:nth-child(2)>span.nav>a.nav:nth-child(2)").first().attr("href")},itemSelector:function(){return $("table.forumline > tbody > tr").has("td > span.postbody")},unreadSelector:function(){return'td > table > tbody > tr > td > a > img[alt="New post"]'},createItemsList:function(){var t=[],e=this;return this.itemSelector().each(function(){t.push({element:this,text:e.getItemText(this),unread:e.getUnreadStatus(this),date:e.getDate(this)})}),t},newItemSelected:function(t){this.currentlySelectedItem=t;var e=$("span.postbody a",t.element);if(e.length>0){for(var n=[],r=0;r<e.length;r++)n.push(e[r]);this.currentlySelectedItemSelectedLink=0,$(n[this.currentlySelectedItemSelectedLink]).addClass("rfsSelectedLink"),this.selectedItemLinks=n}},getItemText:function(t){return $("td > table > tbody > tr > td > span.postbody",t).text().replace(/\s{1,100}/," ").trim()},getUnreadStatus:function(t){return $('td > table > tbody > tr > td > a > img[alt="New post"]',t).length>0},getDate:function(t){var e=$("td > table > tbody > tr > td > span.postdetails",t).text().match(/Posted: (\d{2})\.(\d{2}).(\d{4}) (\d{2}):(\d{2})/);return new Date(e[3],e[2]-1,e[1],e[4],e[5])},getAuthorNick:function(t){return $("td span.name b",t).text()},getAllItems:function(){return null==this.allItems&&(this.allItems=this.createItemsList()),this.allItems},getFilteredItems:function(){var t=new RegExp(this.itemsFilter,"i");return this.getAllItems().filter(e=>e.text.match(t))},selectInitialElement:function(t){for(var e=0;e<t.length;e++){var n=t[e];if(n.unread)return n}return n},arrive:function(){},markItems:function(){this.itemSelector().addClass("rfsItem").has(this.unreadSelector()).addClass("rfsUnreadItem")},getParentUrl:function(){return $("body>table>tbody>tr>td>table>tbody>tr>td>font>p>table>tbody>tr>td:nth-child(2)>span.nav>a.nav:nth-child(2)").first().attr("href")},goToSelectedItem:function(){this.selectedItemLinks&&this.selectedItemLinks.length>0&&window.open($(this.selectedItemLinks[this.currentlySelectedItemSelectedLink]).attr("href"),"_blank")},handleHotkey:function(t){if("r"==t.key){var e={date:this.currentlySelectedItem.date,text:this.currentlySelectedItem.text,author:this.getAuthorNick(this.currentlySelectedItem.element)};localStorage.setItem("rfsReplyObject",JSON.stringify(e)),window.location.href=$('a img[alt="Reply to topic"]').parent().attr("href")}if("q"==t.key){e={date:this.currentlySelectedItem.date,text:this.currentlySelectedItem.text,author:this.getAuthorNick(this.currentlySelectedItem.element)};localStorage.setItem("rfsReplyObject",JSON.stringify(e)),window.location.href=$('a img[alt="Reply with quote"]',this.currentlySelectedItem.element).parent().attr("href")}if("n"==t.key&&(window.location.href=$('a img[alt="Post new topic"]').parent().attr("href")),"e"==t.key){var n=$('td table a img[alt="Edit/Delete this post"]',this.currentlySelectedItem.element).parent().attr("href");n&&(window.location.href=n)}if("l"==t.key){var r=this.currentlySelectedItemSelectedLink+1;if(r>=this.selectedItemLinks.length&&(r=0),r==this.currentlySelectedItemSelectedLink)return;$(this.selectedItemLinks[this.currentlySelectedItemSelectedLink]).removeClass("rfsSelectedLink"),$(this.selectedItemLinks[r]).addClass("rfsSelectedLink"),this.currentlySelectedItemSelectedLink=r}if(188==t.which&&t.shiftKey){var i=$('a:contains("Previous")').first();i.length>0&&(window.location.href=i.attr("href"))}if(190==t.which&&t.shiftKey){var o=$('a:contains("Next")').first();o.length>0&&(window.location.href=o.attr("href"))}}});var contextHandler={currentContext:null,allContexts:null,currentlySelectedItem:null,allItems:null,initialize:function(){this.allContexts=contexts;for(var t=0;t<this.allContexts.length;t++)this.allContexts[t].isCurrentContext()&&(this.currentContext=this.allContexts[t])},arrive:function(){this.currentContext&&(this.currentContext.markItems&&this.currentContext.markItems(),this.currentContext.arrive&&this.currentContext.arrive())},getCurrentContext:function(){return this.currentContext},selectNewItem:function(t){null!=this.currentlySelectedItem&&$(this.currentlySelectedItem.element).removeClass("rfsSelectedItem"),$(t.element).addClass("rfsSelectedItem"),this.currentlySelectedItem=t,this.currentContext.newItemSelected&&this.currentContext.newItemSelected(t),t.element.scrollIntoViewIfNeeded()},goUp:function(){this.currentContext&&(this.currentContext.goUp?this.currentContext.goUp():this.currentContext.getParentUrl&&(window.location.href=this.currentContext.getParentUrl()))},goToSelectedItem:function(){this.currentContext.goToSelectedItem&&this.currentContext.goToSelectedItem(),this.currentlySelectedItem&&(this.currentContext.getItemUrl?window.location.href=this.currentContext.getItemUrl(this.currentlySelectedItem):console.error("Context "+this.currentContext.contextName+" does not support getItemUrl"))},selectNext:function(){var t=this.currentContext.getFilteredItems(),e=t.indexOf(this.currentlySelectedItem)+1;e>=t.length&&(e=0),this.selectNewItem(t[e])},selectPrevious:function(){var t=this.currentContext.getFilteredItems(),e=t.indexOf(this.currentlySelectedItem)-1;e<0&&(e=t.length-1),this.selectNewItem(t[e])},selectInitialElement:function(){if(this.currentContext&&this.currentContext.supportsItems){var t,e,n,r=this.currentContext.getFilteredItems();if(this.currentContext.selectInitialElement)t=this.currentContext.selectInitialElement(r);else for(var i=0;i<r.length;i++)e=t,n=r[i],t=null==e?n:null==n?e:e.unread!=n.unread?e.unread?e:n:e.date>=n.date?e:n;this.selectNewItem(t)}},handleHotKey:function(t){this.currentContext.handleHotkey&&this.currentContext.handleHotkey(t)}},forumMap={configuredMap:null,initialize:function(){var t=localStorage.getItem("rfsForumMap");this.configuredMap=t?JSON.parse(t):this.getEmptyForumMap()},updateMap:function(t,e){for(var n=this.getEmptyForumMap(),r=0;r<t.length;r++)n.forums[r]={forumPosition:r,url:t[r].url};n.indexUrl=e,localStorage.setItem("rfsForumMap",JSON.stringify(n))},getForumUrl:function(t){if(-1==t&&(t=9),this.configuredMap.forums.length<=t)return"";var e=this.configuredMap.forums[t];return e?e.url:""},getForumTopUrl:function(){return this.configuredMap.indexUrl},getEmptyForumMap:function(){return{lastUpdate:new Date,forums:[],indexUrl:""}}},rfsHistory={historyObject:null,initialize:function(){this.historyObject=JSON.parse(localStorage.getItem("frs_history"))||{events:[],creationTime:new Date},this.addCurrentPage()},getHistory:function(){return this.historyObject},addCurrentPage:function(){this.historyObject.events.push({time:new Date,url:window.location.href,title:document.title}),localStorage.setItem("frs_history",JSON.stringify(this.historyObject))}};function isDate(t){return"[object Date]"===Object.prototype.toString.call(t)}function dateCompareToMinute(t,e){return!(!isDate(t)||!isDate(e))&&(t.getFullYear()==e.getFullYear()&&(t.getMonth()==e.getMonth()&&(t.getDate()==e.getDate()&&(t.getHours()==e.getHours()&&t.getMinutes()==e.getMinutes()))))}$(document).keydown(function(t){var e=!1;if(t.which>=48&&t.which<59&&t.ctrlKey&&!t.altKey){var n=t.which-48;window.location.href=forumMap.getForumUrl(n-1),e=!0}else 220==t.which&&t.ctrlKey&&!t.altKey?(window.location.href=forumMap.getForumTopUrl(),e=!0):188!=t.which&&190!=t.which||t.shiftKey?13!=t.which||t.ctrlKey?78==t.which||82==t.which||79==t.which&&contextHandler.goUp():(contextHandler.goToSelectedItem(),e=!0):(188==t.which?contextHandler.selectPrevious():contextHandler.selectNext(),e=!0);e||contextHandler.handleHotKey(t)}),rfsHistory.initialize(),contextHandler.initialize(),forumMap.initialize(),contextHandler.arrive(),window.onload=function(){contextHandler.selectInitialElement()},document.rfsHasInitialized=!0; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Funksjoner i RBKweb Forum Suite
Hva RBKweb Forum Suite er for noe
RBKweb Forum Suite er et såkalt userscript som legger til funksjonalitet og modifiserer en webside etter smak og behag. RBKweb-forumet bruker en versjon av phpbb som ikke lenger er toppmoderne og dermed mangler en del funksjonalitet som man kjenner fra vår tids webapplikasjoner. RFS forsøker å fylle noen av disse hullene.
Hva slags funksjonalitet RFS gir
Følgende funksjoner er implementert p.t.
Globale funksjoner
Disse funksjonene skal være tilgjengelige uansett hva slags forumside man er på.
Forumlista
Forumlista er hovedsiden der man ser de ulike underforumene som "Sportslig avdeling", "På sidelinja" osv.
Inne i et underforum
I en tråd / et emne
Posting-siden (ny post/svar/new topic/quote)
Merknader
Privatlivets fred og sikkerhet
RFS lagrer/sender ingen personlig identifiserbar informasjon om deg. Scriptet bruker HTML5 localStorage for å lagre konfigurasjon som er nødvendig for å fungere riktig, inkludert en historikk over hvilke sider du har vært innom på forumet. Det finnes ingen måte for meg eller andre å stjele denne informasjonen. Historikken er nødvendig for "opp/tilbake"-type funksjonalitet i noen tilfeller - f.eks. har en del av sidene hvor man skriver nye innlegg lite info om hvor man kom dit fra. En del av denne funksjonaliteten er under utvikling.
Testing av scriptet på ulike systemer
RFS er ikke testet på alle kombinasjoner av operativsystemer, userscript-motorer og browsere. Dersom du bruker en kombinasjon vi ikke har testet, hører vi gjerne om det - uansett om det virker eller ikke!
Dersom noe funker dårlig, lag gjerne et issue på Github med så mye informasjon som mulig.
Tankedump
Context lifecycle
For å flytte mest mulig funksjonalitet til contextHandler trenger man støttefunksjoner som trekker ut relevant info.
contextHandler: