1/** 2 Startpage Reworked 3 ================== 4 5 by Christian Brassat, 6 reusing code by Jukka Svahn 7*/ 8 9/** 10 Released under MIT License 11 12 Copyright (c) 2010 Jukka Svahn, Christian Brassat 13 <http://rahforum.biz> 14 <http://crshd.cc> 15 16 Permission is hereby granted, free of charge, to any person obtaining a copy 17 of this software and associated documentation files (the "Software"), to deal 18 in the Software without restriction, including without limitation the rights 19 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 copies of the Software, and to permit persons to whom the Software is 21 furnished to do so, subject to the following conditions: 22 23 The above copyright notice and this permission notice shall be included in 24 all copies or substantial portions of the Software. 25 26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 THE SOFTWARE. 33*/ 34 35/* Settings *\ 36\*==========*/ 37var settings = { 38 "navigation": { 39 "newWindow": true 40 }, 41 42 "search": { 43 "engines": [ 44 ["http://www.google.com/search", "q", "Google", "sg"], 45 ["http://www.google.com/images", "q", "Google Images", "si"], 46/* ["http://search.yahoo.com/search", "p", "Yahoo", "sy"], */ 47 ["http://wikipedia.org/w/index.php", "w", "Wikipedia", "sw"], 48/* ["http://www.dict.cc", "s", "dict.cc", "sd"], 49 ["http://dict.leo.org", "search", "leo", "sl"], 50 ["http://www.flickr.com/search", "q", "flickr", "sf"], 51 ["http://browse.deviantart.com/", "q", "deviantArt", "sa"] 52*/ 53 ], 54 "focusSearch": false 55 }, 56 57 "clock": { 58 "showClock": true 59 }, 60 61 "animation": { 62 "hideLinks": false 63 }, 64 65 "icons": { 66 "showIcons": true 67 } 68}; 69 70/* Clock *\ 71\*=========*/ 72function updateClock() { 73 var currentTime = new Date (); 74 var currentHours = currentTime.getHours (); 75 var currentMinutes = currentTime.getMinutes (); 76 var currentSeconds = currentTime.getSeconds (); 77 var currentDate = currentTime.getSeconds (); 78 var month = currentTime.getMonth(); 79 var day = currentTime.getDate() ; 80 var date = currentTime.getDay() ; 81 var year = currentTime.getFullYear(); 82 var months = new Array ('January','February','March','April','May','June','July','August','September','October','November','December'); 83 var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); 84 85 // Pad the minutes and seconds with leading zeros, if required 86 currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes; 87 currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds; 88 89 // Choose either "AM" or "PM" as appropriate 90 var timeOfDay = (currentHours < 12) ? "AM" : "PM"; 91 92 // Convert the hours component to 12-hour format if needed 93 currentHours = (currentHours > 12) ? currentHours - 12 : currentHours; 94 95 // Convert an hours component of "0" to "12" 96 currentHours = (currentHours == 0) ? 12 : currentHours; 97 98 // Compose the string for display 99 var currentTimeString = days[date] + " " + months[month] + " " + day + " " + year + " - " + currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay; 100 101 // Fill '#clock' div with time 102 $("#clock").html(currentTimeString); 103} 104 105 106function searchBox(url, name, placeholder) { 107 var string = '<form method="get" action="' + url + '">' 108 + '<input type="text" id="g" name="' + name + '" placeholder="' + placeholder + '" maxlength="255" value="">' 109 + '<input type="submit" value="Go">' 110 + '</form>'; 111 return string; 112} 113 114$(document).ready(function() { 115 116 var shortcuts = {}; 117 118 /* Get Links *\ 119 \*=============*/ 120 var linkString = $('body').text(); 121 122 /* Clear Page *\ 123 \*==============*/ 124 $('body').empty(); 125 126 /* Create Array from linkString *\ 127 \*================================*/ 128 var linkArray = linkString.split("\n"); 129 130 /* Go thru Array *\
131 \*=================*/ 132 var i; 133 var count = 1; 134 var html = ''; 135 136 for(i in linkArray) { 137 138 /* Get line *\ 139 \*============*/ 140 var line = jQuery.trim(linkArray[i]); 141 142 // If line is empty, skip 143 if(!line) continue; 144 145 /* If it doesn't contain "://", *\ 146 |* it's not a URL *| 147 \*================================*/ 148 if(/:\/\//.test(line) != true) { 149 if(count > 1) { 150 html = html + '</div>'; 151 } 152 html = html + '<div class="block"><h1>' + line + '</h1><ul>'; 153 count++; 154 continue; 155 } 156 157 /* Split URL, Title and icon (if any) *\ 158 \*=======================*/ 159 var lineArray = line.split(" || "); 160 var url = lineArray[0]; 161 var title = lineArray[1]; 162 163 var icon = ""; 164 if (lineArray[3]) { 165 icon = lineArray[3]; 166 } 167 168 /* Add to shortcuts array *\ 169 \*=========================*/ 170 if(lineArray[2]) { 171 shortcuts[lineArray[2]] = "'"+url+"'"; 172 } 173 174 /* Prepares HTML code for showing icon *\ 175 \*=====================================*/ 176 var iconHtml = ''; 177 if (settings.icons.showIcons && icon) { 178 iconHtml = '<img src="' + icon + '"/>'; 179 } 180 181 /* Add HTML code *\ 182 \*=================*/ 183 if(settings.navigation.newWindow) { 184 html = html + '<li>' + iconHtml + '<a href="' + url + '" target="_blank">' + title + '</a></li>' 185 } 186 else { 187 html = html + '<li>' + iconHtml + '<a href="' + url + '">' + title + '</a></li>' 188 } 189 } 190 191 /* Add generated content to page *\ 192 \*=================================*/ 193 html = html + '</ul></div>'; 194 $('body').append(html); 195 196 197 /* Animation Time! *\ 198 \*===================*/ 199 200 /* Hide lists *\ 201 \*==============*/ 202 if (settings.animation.hideLinks) { 203 $('ul').slideUp(); 204 205 /* Show on hover *\ 206 \*=================*/ 207 $('.block').mouseenter(function() { 208 $('ul', this).stop().slideDown(); 209 }); 210 211 /* Hide on unhover *\ 212 \*===================*/ 213 $('.block').mouseleave(function() { 214 $('ul', this).stop().slideUp(); 215 }); 216 } 217 218 219 /* Search Engines *\ 220 \*==================*/ 221 222 var search = '<div id="searches">'; 223 224 for (var i = 0; i < settings.search.engines.length; i++) { 225 var engine = settings.search.engines[i]; 226 search = search + searchBox(engine[0], engine[1], engine[2]); 227 if(engine[3]) { 228 var jsSearchUrl=engine[0]+"?"+engine[1]+"="; 229 var jsSearchPrompt="prompt('Search "+engine[2]+":')"; 230 var jsSearch="'"+jsSearchUrl+"'+"+jsSearchPrompt; 231 shortcuts[engine[3]] = jsSearch; 232 } 233 } 234 235 search = search + '</div>'; 236 237 /* Add to page *\ 238 \*===============*/ 239 $('body').append(search); 240 if(settings.search.focusSearch) { 241 var searchDiv = document.getElementById ('searches'); 242 $(searchDiv.firstChild.firstChild).focus(); 243 } 244 245 /* Clock *\ 246 \*=========*/ 247 248 if(settings.clock.showClock) { 249 // Add empty '#clock' div 250 $('body').append('<div id="clock"></div>'); 251 252 // Update clock 253 setInterval('updateClock()', 1000); 254 } 255 256 257 /* Keybindings *\ 258 \*===============*/ 259 260 var typed = ''; 261 var shortcutArray = Object.keys(shortcuts); 262 var typedDate = new Date(); 263 264 // Check if we typed a keybinding 265 function hasSubstring(element) { 266 var index = typed.indexOf(element); 267 if(index >= 0) { 268 var sliced = typed.slice(index, typed.length); 269 typed = ''; // Clean typed, so that we can watch for the next keybinding 270 if(settings.navigation.newWindow) { 271 window.open(eval(shortcuts[sliced])); 272 } else { 273 window.location.replace(eval(shortcuts[sliced])); 274 } 275 } 276 } 277 278 // React on keypress 279 $(window).keypress(function(e) { 280 // If we're in an input, we don't want to interpret the keypresses 281 $('input').keypress(function(e) { 282 e.stopPropagation(); 283 }); 284 var nowDate = new Date(); 285 var diffMs = (nowDate - typedDate); 286 if (diffMs > 1000) { 287 typed = String.fromCharCode(e.which); 288 } else { 289 typed = typed + String.fromCharCode(e.which); 290 } 291 typedDate = new Date(); 292 shortcutArray.some(hasSubstring); 293 }); 294 295});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.