📄 gsnewsbar.js
字号:
listItem.results = new Array(); listItem.errorCount = 0; listItem.cacheCount = 0; return listItem;}GSnewsBar.prototype.switchToListItem = function(i) { // if this is from a static query term, then just return if (i == -1) { return false; } // reset selcted class of previous item // note, first time through this sets // node 0 if (this.executeList[this.currentIndex].node) { this.cssSetClass(this.executeList[this.currentIndex].node, this.CL_STATUSITEM); } this.currentIndex = i; if (this.executeList[this.currentIndex].node) { this.cssSetClass(this.executeList[this.currentIndex].node, this.CL_STATUSITEM_SELECTED); } var queryTerm = this.executeList[this.currentIndex].query; var cacheResults = false; var currentListItem = null; currentListItem = this.executeList[this.currentIndex]; // if the listItem has no cached results, OR if // we have used the cached results several times // already, initiate a real search if (currentListItem.cacheCount == 0 || currentListItem.cacheCount > this.cacheLifetime ) { currentListItem.cacheCount = 0; this.executeInternal(this.executeList[this.currentIndex].query); } else { // we have cached results and they are within the programmed // life time so use them. e.g., fake a search currentListItem.cacheCount++; this.ns.results = new Array(); for (var ri=0; ri < currentListItem.results.length; ri++) { this.ns.results.push(currentListItem.results[ri]); } this.searchComplete(true); } return false;}GSnewsBar.prototype.populateStatusRoot = function() { this.removeChildren(this.statusRoot); var sbClass = this.CL_STATUSBOX; if (this.executeList.length == 1) { sbClass = this.CL_STATUSBOX_ONEITEM; } this.statusBox = this.createDiv(null, sbClass); this.statusRoot.appendChild(this.statusBox); if ( this.executeList.length > 0) { for (var i=0; i < this.executeList.length; i++ ) { var listItem = this.executeList[i]; var displayTerm = listItem.query; var cl; if (this.verticalMode) { cl = this.createClickLink(displayTerm, null, this.CL_STATUSITEM); // add click handler... cl.onclick = this.methodClosure(this, GSnewsBar.prototype.switchToListItem, [i] ); } else { var gwsUrl = "http://news.google.com/nwshp?source=uds&q=" + encodeURIComponent(displayTerm); cl = this.createClickLink(displayTerm, gwsUrl, this.CL_STATUSITEM, GSearch.strings["more-results"] + ": " + displayTerm); } listItem.node = cl; this.statusBox.appendChild(cl); if (i+1 < this.executeList.length) { if (this.verticalMode) { this.statusBox.appendChild(this.createSpan(" ", this.CL_STATUSITEMSEP)); } } } }}/** * Static Helper Method*/GSnewsBar.methodCallback = function(object, method) { return function() { return method.apply(object, arguments); }}/** * Class methods*/GSnewsBar.prototype.methodClosure = function(object, method, opt_argArray) { return function() { return method.apply(object, opt_argArray); }}GSnewsBar.prototype.createDiv = function(opt_text, opt_className) { var el = document.createElement("div"); if (opt_text) { el.innerHTML = opt_text; } if (opt_className) { el.className = opt_className; } return el;}GSnewsBar.prototype.createSpan = function(opt_text, opt_className) { var el = document.createElement("span"); if (opt_text) { el.innerHTML = opt_text; } if (opt_className) { el.className = opt_className; } return el;}GSnewsBar.prototype.removeChildren = function(parent) { while (parent.firstChild) { parent.removeChild(parent.firstChild); }}GSnewsBar.prototype.removeChild = function(parent, child) { parent.removeChild(child);}GSnewsBar.prototype.cssSetClass = function(el, className) { el.className = className;}GSnewsBar.prototype.createClickLink = function(text, opt_href, opt_className, opt_tooltip) { var el = document.createElement("a"); if (opt_href) { el.href = opt_href; el.target = this.linkTarget; } else { el.href = "_nolink_"; } el.appendChild(document.createTextNode(text)); if (opt_className) { el.className = opt_className; } if (opt_tooltip) { el.title = opt_tooltip; } return el;}GSnewsBar.prototype.br_AgentContains_ = function(str) { if (str in this.br_AgentContains_cache_) { return this.br_AgentContains_cache_[str]; } return this.br_AgentContains_cache_[str] = (navigator.userAgent.toLowerCase().indexOf(str) != -1);}GSnewsBar.prototype.br_IsIE = function() { return this.br_AgentContains_('msie');}GSnewsBar.prototype.br_IsKonqueror = function() { return this.br_AgentContains_('konqueror');}GSnewsBar.prototype.br_IsOpera = function() { return this.br_AgentContains_('opera');}GSnewsBar.prototype.br_IsSafari = function() { return this.br_AgentContains_('safari') || this.br_IsKonqueror();}GSnewsBar.prototype.br_IsNav = function() { return !this.br_IsIE() && !this.br_IsSafari() && this.br_AgentContains_('mozilla');}GSnewsBar.prototype.br_IsWin = function() { return this.br_AgentContains_('win');}GSnewsBar.prototype.br_IsMac = function() { return this.br_AgentContains_('macintosh') || this.br_AgentContains_('mac_powerpc');}GSnewsBar.prototype.br_IsLinux = function() { return this.br_AgentContains_('linux');}GSnewsBar.prototype.setOpacity = function(element, opacity) { if (this.ieMode) { /* // on ie6, if the container doesn't have a background color // and cleartype is enabled, the text looks terrible // do not fade on ie6... // We tried limiting this to IE7, but that was a disaster // as well. IE7 seems to disable font-smoothing when you do this // making the newsbar look terrible. Fix is to just not do the // fade effect on IE at all if (navigator.userAgent.indexOf("MSIE 7") != -1) { var normalized = Math.round(opacity * 100); element.style.filter = "alpha(opacity=" + normalized + ");"; } */ return; } else { element.style.opacity = opacity; }}GSnewsBar.prototype.getNodeWidth = function(node) { return node.offsetWidth;}/** * Blogger B2 has a problem in its html/javascript widget * where it will throw away link tags. This is how the * wizards used to load their css. This piece of code does * its best to work around this problem and will try to * reload missing css */GSnewsBar.checkAndFixBloggerCSS = function(){ if ( window._uds_nbw_donotrepair ) { return; } // same for all solutions var gsearchCssPattern = /http:\/\/www\.google\.com\/uds\/css\/gsearch\.css/; var gsearchCss = "http://www.google.com/uds/css/gsearch.css"; // adjust for each solution... var selfWizardPattern = /file=uds\.js.*?&source=uds-nbw/; var selfNewModePattern = /gsnewsbar.js\?mode=new/; var selfCss = "http://www.google.com/uds/solutions/newsbar/gsnewsbar.css"; var loadCss = function(css) { document.write('<link href="' + css + '" rel="stylesheet" type="text/css"/>'); } var windowRef = window.location.href; var inBlogger = false; if (windowRef && windowRef != "" && windowRef.match(/http:\/\/.*?\.blogspot\.com/)) { inBlogger = true; } if (!inBlogger) { return; } // ok, so we are in blogger // now, look to see if we are running from our own // wizard code var selfNewMode = false; var selfWizard = false; var scripts = document.getElementsByTagName("script"); if (scripts && scripts.length > 0) { for (var i=0; i < scripts.length; i++) { var src = scripts[i].src; if (src.match(selfWizardPattern)) { selfWizard = true; } if (src.match(selfNewModePattern)) { selfNewMode = true; } } } if (!selfWizard) { return; } if (selfNewMode) { return; } // ok, we are running in our own wizard, in blogger // now, we need to make sure our CSS is loaded, only // we can't really know for sure, because the css tag // is next. So, what we do is look for gsearch.css (or // the global that says gsearch.css was missing because // another wizard already had to fix things up var gsearchCssMissing = true; var selfCssMissing = true; if ( !window._uds_wizards_gsearchCssMissing ) { // no other wizard discovered gsearch.css missing // so either no one else has run, or its not missing // look for gsearch.css. If its missing, load it and // load ourselves. If its found, assume ours is there as well var links = document.getElementsByTagName("link"); if (links && links.length > 0) { for (var i=0; i < links.length; i++) { if (links[i].href.match(gsearchCssPattern) ) { gsearchCssMissing = false; break; } } } if (gsearchCssMissing) { window._uds_wizards_gsearchCssMissing = true; loadCss(gsearchCss); loadCss(selfCss); } } else { // if someone else marked gsearch.css missing, then we should assume // that we are missing too and self load loadCss(selfCss); }}GSnewsBar.checkAndFixBloggerCSS();GSnewsBar.cloneObject = function(obj) { var res = new Object(); for (var prop in obj) { switch(typeof(obj[prop])) { case "object": if (typeof(obj[prop].nodeType) == "undefined" || typeof(obj[prop].cloneNode) == "undefined") { res[prop] = GSnewsBar.cloneObject(obj[prop]); } else { try { res[prop] = obj[prop].cloneNode(true); } catch (e) { res[prop] = GSnewsBar.cloneObject(obj[prop]); } } break; default: res[prop] = obj[prop]; break; } } return res;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -