最近安装maxthon2.0,用来其delicious sidebar插件,原来工作正常,现在出现问题,卸载house重新安装sidebar,出现验证无法通过。检查其Delicious.js代码,由于原有网址http://del.icio.us,改为http://delicious.com/,所以无法验证,验证时必须有http://delicious.com/yourname网页打开,而且添加网址时标题不能超过255个字节。修改js如下:
- /**************************
- Del.icio.us Sidebar
- By Neo101
- Version 1.2.1
- **************************/
- checkSettingsFile()
- var authUser = readSetting('authUser')
- var split = authUser.split('%20')
- var userName = split ? split[0] : ''
- var showTooltip = readSetting('showTooltip', '1')
- var autoUpdateTime = parseInt( readSetting('autoUpdateTime', '0') )
- if( isNaN(autoUpdateTime) ){
- autoUpdateTime = 0
- }
- var sortTags = readSetting('sortTags', '1')
- var sortFavorites = readSetting('sortFavorites', '1')
- var useBundles = readSetting('useBundles', '1')
- var baseURL = 'https://api.del.icio.us/v1/'
- var favoritesCache = 'cache/favorites.html'
- var favoritesHTML = ''
- var posts = new Array()
- var bundleArray = new Array()
- var branch = 0
- var xmlhttp
- var editElement
- var isAddFavorite = true
- var TRUE = '1'
- var FALSE = '0'
- // var deliciousURL = 'http://del.icio.us/';
- var deliciousURL = 'http://delicious.com/'
- var deliciousSettingURL = 'https://secure.delicious.com/settings/'
- window.onload = function(){
- if(authUser == ''){
- displaySettings()
- document.getElementById('settingsLinks').style.display = 'none'
- document.getElementById('mainSettings').style.display = 'none'
- document.getElementById('links').style.display = 'none'
- document.getElementById('aboutDelicious').style.display = ''
- } else {
- viewFavorites()
- getLastUpdateTime()
- setLinks()
- }
- setAutoUpdate()
- //clean old login data
- if(readSetting('userName', '') != ''){
- writeSetting('userName', '')
- writeSetting('password', '')
- }
- }
- function setLinks(){
- document.getElementById('yourFavoritesLink').href = deliciousURL + userName
- document.getElementById('yourNetworkLink').href = deliciousURL + 'network/' + userName
- document.getElementById('importBookmarksLink').href = deliciousSettingURL + userName + '/bookmarks/import'
- document.getElementById('exportBookmarksLink').href = deliciousSettingURL + userName + '/bookmarks/export'
- document.getElementById('editBundleLink').href = deliciousSettingURL + userName + '/tags/bundle?noredir'
- }
- function setAutoUpdate(){
- if(autoUpdateTime < 5){
- return
- }
- var time = autoUpdateTime * 1000 * 60
- window.setInterval(getLastUpdateTime, time)
- }
- function loadXMLDoc(url, type, stateChange, data){
- if(authUser == ''){
- showError('User information not defined!')
- return
- }
- try{
- xmlhttp = external.max_activex(SECURITY_ID, "Microsoft.XMLHTTP")
- }
- catch(err){
- try{
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
- }
- catch(err){
- showError('Could not load ActiveX object')
- }
- }
- xmlhttp.onreadystatechange = stateChange
- xmlhttp.open("POST", url, true, 'cookie', 'cookie')
- xmlhttp.setRequestHeader('User-Agent', 'Maxthon del.icio.us sidebar plugin')
- xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
- xmlhttp.setRequestHeader('Referrer', 'Maxthon del.icio.us sidebar plugin')
- var data = '_user=' + authUser
- xmlhttp.send(data)
- }
- function checkReadyState(obj){
- if(obj.readyState == 4){
- //alert(obj.responseText)
- if(obj.status == 200 || obj.status == 201){
- return true;
- }
- else if(obj.status == 401 || obj.status == 403){
- var message = 'Could not login. Please check your '+
- '<a href="#" οnclick="displaySettings()" style="color:red;text-decoration:underline">login information!</a>'
- showError(message)
- document.getElementById('favorites').innerHTML = message
- writeFile(favoritesCache, '')
- }
- else if(obj.status == 503){
- showError('Error 503: Please try again in a couple of minutes..')
- }
- else{
- showError(obj.status + ' ' + obj.responseText);
- }
- }
- }
- function getLastUpdateTime(){
- var url = baseURL + 'posts/update?' + Math.round(Math.random() * 1000)
- showError('Checking for updates...')
- loadXMLDoc(url, 'getLastUpdateTime', onResponseGetLastUpdateTime)
- }
- function onResponseGetLastUpdateTime(){
- if( ! checkReadyState(xmlhttp) ){
- return
- }
- var responseXML = xmlhttp.responseXML
- if( responseXML == null ){
- showError('Error loading XML')
- return
- }
- try{
- var lastUpdateTime = responseXML.getElementsByTagName("update")[0].getAttribute('time')
- } catch(err){
- showError('bad response getting time...')
- alert(xmlhttp.responseText)
- return
- }
- var previousUpdateTime = readSetting('UpdateTime')
- if( previousUpdateTime != lastUpdateTime){
- showError('Update available')
- writeSetting('UpdateTime', lastUpdateTime)
- window.setTimeout(updateFavorites, 1000)
- }else {
- showError('No favorite updates')
- }
- }
- function viewFavorites(){
- var html = unescape( readFile(favoritesCache) )
- if(html == null || html == ''){
- writeSetting('UpdateTime', '')
- return
- }
- favoritesHTML = html
- currentlyOpenFolder = null
- document.getElementById('favorites').innerHTML = html
- }
- function getBundles(){
- var url = baseURL + 'tags/bundles/all?' + Math.round(Math.random() * 1000)
- showError('Checking for bundles...')
- loadXMLDoc(url, 'getBundles', onResponseGetBundles)
- }
- function onResponseGetBundles(){
- if( ! checkReadyState(xmlhttp) ){
- return
- }
- var responseXML = xmlhttp.responseXML
- if( responseXML == null ){
- showError('Error loading Bundle XML')
- return
- }
- bundleArray = new Array()
- var bundleTags = responseXML.getElementsByTagName("bundles")[0].childNodes
- for(var i=0; i<bundleTags.length; i++){
- bundleArray.push( new Array( bundleTags[i].getAttribute('name') , bundleTags[i].getAttribute('tags') ) )
- }
- window.setTimeout(downloadFavorites, 1000)
- }
- function updateFavorites(){
- if(useBundles == '1'){
- getBundles()
- } else {
- downloadFavorites()
- }
- }
- function downloadFavorites(){
- var url = baseURL + 'posts/all?' + Math.round(Math.random() * 1000)
- showError('Updating...')
- loadXMLDoc(url, 'viewFavorites', onResponseViewFavorites)
- }
- function onResponseViewFavorites(){
- if( ! checkReadyState(xmlhttp) ){
- return
- }
- var responseXML = xmlhttp.responseXML
- if( responseXML == null ){
- showError('Error loading XML')
- return
- }
- var response = ''
- posts = new Array()
- items = responseXML.getElementsByTagName("post");
- if(items && items.length != 0 ){
- for(var j=0; j < items.length; j++) {
- addPost(items[j], posts)
- }
- }
- else{
- response += '<b>No favorites found</b>'
- }
- var tags = new Array()
- addPostsToTags( posts, tags )
- if(sortTags == '1'){
- tags.sort()
- }
- response += writeTree( tags )
- writeFile(favoritesCache, escape( response ))
- favoritesHTML = response
- showError('Favorites Downloaded')
- document.getElementById('favorites').innerHTML = response
- currentlyOpenFolder = null
- document.getElementById('searchbox').value = ''
- }
- function titleSort(a, b){
- try{
- a = a.description.toLowerCase()
- b = b.description.toLowerCase()
- if(a < b){
- return -1
- } else {
- return 1
- }
- }
- catch(err){
- return 1
- }
- }
- function addPostsToTags( postsArray, tagsArray ){
- for(var i=0; i<postsArray.length; i++){
- var tags = postsArray[i].tag.toLowerCase()
- var tagArray = tags.split(' ')
- for(var j=0; j<tagArray.length; j++){
- var position = inArray(tagArray[j], tagsArray)
- if( position >= 0 ){
- tagsArray[position][1].push( postsArray[i] )
- } else {
- tagsArray.push(new Array( tagArray[j], new Array( postsArray[i] ) ) )
- }
- }
- }
- }
- function writeTree( tagsArray ){
- var html = ''
- var unfiledHtml = ''
- for(var i=0; i<bundleArray.length; i++){
- var name = bundleArray[i][0]
- var tags = bundleArray[i][1].toLowerCase().split(' ')
- var branchNumber = branch + 10000
- html += returnFolderHtml(branchNumber, name, true)
- html += addTags( tags , tagsArray )
- html += '</div>/n'
- branch++
- }
- for( var i=0; i<tagsArray.length; i++ ){
- if(tagsArray[i][0] == 'system:unfiled'){
- unfiledHtml = addLinks( tagsArray[i][1] )
- continue
- }
- html += returnTagHtml(tagsArray[i], true)
- }
- html += unfiledHtml
- return html
- }
- function returnFolderHtml(number, name, isBundle){
- if(isBundle != null){
- var imageSrc = 'images/bundleClosed.gif'
- } else {
- var imageSrc = 'images/folderClosed.gif'
- }
- return '<div class="trigger" οnclick="expandCollapse(' + number + ')" οncοntextmenu="showContextMenu(this);return false" '+
- 'οnmοuseοver="this.style.textDecoration=/'underline/'" οnmοuseοut="this.style.textDecoration=/'none/'">'+
- '<img src="' + imageSrc + '" border="0" id="folder' + number + '">'+
- name +
- '</div>/n<div class="branch" id="branch' + number + '">'
- }
- function addTags( tags, tagsArray){
- var html = ''
- for(var i=0; i<tags.length; i++){
- var position = inArray(tags[i], tagsArray)
- if(position > -1){
- html += returnTagHtml( tagsArray[position] )
- }
- tagsArray.splice(position, 1)
- }
- return html
- }
- function returnTagHtml(tag, isHighBranch){
- if(isHighBranch != null){
- var branchNumber = branch + 10000
- } else {
- var branchNumber = branch
- }
- var html = returnFolderHtml(branchNumber, tag[0] )
- html += addLinks( tag[1] )
- html += '</div>/n'
- branch++
- return html
- }
- function addLinks(items){
- var html = ''
- if(sortFavorites == '1'){
- items.sort(titleSort)
- }
- for(var i=0; i<items.length; i++){
- var item = items[i]
- html += '<div class=linkDiv οncοntextmenu="showContextMenu(this);return false">'+
- '<a class=link href="' + item.href + '" target=_blank title="' + item.tooltip + '" '+
- 'οnmοuseοver="showLink(this.href)" οnmοuseοut="hideLink()" '+
- 'extended="' + item.extended + '" tag="' + item.tag + '" hashCode="' + item.hash + '">'+
- '<img src="images/page.gif">' +
- item.description +
- '</a>'+
- '</div>/n'
- }
- return html
- }
- function addPost( item , array){
- var href = item.getAttribute('href')
- var description = item.getAttribute('description')
- var tag = item.getAttribute('tag')
- var time = item.getAttribute('time')//.substring(0,10)
- var hash = item.getAttribute('hash')
- var extended = item.getAttribute('extended')
- if(extended == null){
- extended = ''
- }
- // times like 2004-09-16T00:00:00Z
- var date = new Date()
- date.setISO8601(time)
- time = date.toLocaleString()
- if(showTooltip == '1'){
- var tooltip = 'Added: ' + time
- var MAX_DESCRIPTION_LENGTH = 30
- if(description.length > MAX_DESCRIPTION_LENGTH){
- tooltip = description + '/n' + tooltip
- }
- if(extended){
- tooltip += '/nNote: ' + extended
- }
- } else {
- var tooltip = ''
- }
- array.push( {'href':href,
- 'description':description,
- 'tag':tag,
- 'time':time,
- 'hash':hash,
- 'extended':extended,
- 'tooltip':tooltip
- } )
- }
- function onResponsePostFavorite(){
- if( ! checkReadyState(xmlhttp) ){
- return
- }
- var responseXML = xmlhttp.responseXML
- if( responseXML == null ){
- showError('Error loading XML')
- return
- }
- try{
- var response = responseXML.getElementsByTagName("result")[0].getAttribute('code')
- } catch(err){
- showError('bad response Posting...')
- alert(xmlhttp.responseText)
- return
- }
- if(response == 'done'){
- showError('Favorite added!')
- window.setTimeout('getLastUpdateTime()', 1000)
- }
- }
- function deleteFavorite(url){
- var url = baseURL + 'posts/delete?url=' + encodeURIComponent( url )
- showError('deleting...')
- loadXMLDoc(url, 'deleteFavorite', onResponseDeleteFavorite)
- }
- function onResponseDeleteFavorite(){
- if( ! checkReadyState(xmlhttp) ){
- return
- }
- var responseXML = xmlhttp.responseXML
- if( responseXML == null ){
- showError('Error loading XML')
- return
- }
- try{
- var response = responseXML.getElementsByTagName("result")[0].getAttribute('code')
- } catch(err){
- showError('bad response Deleting...')
- alert(xmlhttp.responseText)
- return
- }
- if(response == 'done'){
- showError('Favorite deleted!')
- window.setTimeout('getLastUpdateTime()', 1000)
- } else {
- showError('Error: ' + response)
- }
- }
- function getCurrentWebsiteURL(){
- return external.get_tab(SECURITY_ID, external.cur_sel).document.URL
- }
- function getCurrentWebsiteTitle(){
- return external.get_tab(SECURITY_ID, external.cur_sel).document.title
- }
- function getEditWebsiteURL(){
- return editElement.href
- }
- function getEditWebsiteTitle(){
- return editElement.innerText
- }
- function getEditWebsiteNotes(){
- return editElement.extended
- }
- function getEditWebsiteTags(){
- return editElement.tag
- }
- function displaySettings(){
- loadSettings()
- document.getElementById('favorites').style.display = 'none'
- document.getElementById('settings').style.display = ''
- document.getElementById('message').style.display = 'none'
- document.getElementById('menu').style.display = 'none'
- document.getElementById('showSettings').onclick = function(){hideSettings()}
- }
- function getDeliciousCookie(){
- var deliciousWindow = getDeliciousWindow()
- if(deliciousWindow == null){
- window.open(deliciousURL);
- }
- var deliciousWindow = getDeliciousWindow()
- if(deliciousWindow){
- if(deliciousWindow.document.readyState == 'complete'){
- saveCookie(deliciousWindow.document.cookie)
- } else {
- deliciousWindow.document.onreadystatechange = function(){
- if(deliciousWindow.document.readyState == 'complete'){
- saveCookie(deliciousWindow.document.cookie)
- }
- }
- }
- }
- }
- function saveCookie(cookie){
- var match = cookie.match(/.*?_user=(.*?)(;|$)/)
- if(match){
- var user = match[1]
- writeSetting('authUser', user)
- alert('Authenticated!')
- } else {
- writeSetting('authUser', '')
- alert('Cookie problem!/nCould not authenticate you./nMake sure you are logged into delicious.com')
- }
- }
- function getDeliciousWindow(){
- var win
- for(var i=0; i<external.tab_count; i++){
- win = external.get_tab(SECURITY_ID, i)
- if(win.document.URL.indexOf(deliciousURL) != -1){
- return win
- }
- }
- return null
- }
- function hideSettings(){
- document.getElementById('favorites').style.display = ''
- document.getElementById('settings').style.display = 'none'
- document.getElementById('message').style.display = 'none'
- document.getElementById('menu').style.display = ''
- document.getElementById('showSettings').onclick = function(){displaySettings()}
- }
- function cancel(){
- hideSettings()
- if(authUser == ''){
- var message = '<a href="javascript:displaySettings()">Login first!</a>'
- document.getElementById('favorites').innerHTML = message
- }
- }
- function save(){
- /*if(userName != userNameNew){
- writeFile(favoritesCache, '')
- }*/
- writeSetting('UpdateTime', '')
- saveSettings()
- location.reload()
- }
- function inArray( text, array ){
- for(var i=0; i<array.length; i++){
- if(text == array[i][0]){
- return i
- }
- }
- return -1
- }
- function loadSettings(){
- var allInputTags = document.getElementsByTagName('input')
- for(var i=0; i<allInputTags.length; i++) {
- if(allInputTags[i].type=='checkbox') {
- if(readSetting(allInputTags[i].id+'') == TRUE){
- allInputTags[i].checked = true
- }
- else {
- allInputTags[i].checked = false
- }
- }
- if(allInputTags[i].type == 'text' && allInputTags[i].id != 'searchbox' && allInputTags[i].onkeydown == null){
- allInputTags[i].value = eval(allInputTags[i].id+'')
- }
- }
- }
- function saveSettings(){
- var allInputTags = document.getElementsByTagName('input');
- for(var i=0; i<allInputTags.length; i++) {
- if(allInputTags[i].type == 'checkbox') {
- if(allInputTags[i].checked == true){
- writeSetting(allInputTags[i].id+'', TRUE)
- }
- else {
- writeSetting(allInputTags[i].id+'', FALSE)
- }
- }
- if(allInputTags[i].type == 'text' && allInputTags[i].id != 'searchbox' && allInputTags[i].onkeydown == null) {
- writeSetting(allInputTags[i].id+'', allInputTags[i].value)
- }
- }
- }