-
-
Save achimbode/97683 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
/* | |
Copyright (c) 2009 Achim Bode | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. | |
*/ | |
CmdUtils.CreateCommand({ | |
name: "know", | |
homepage:"http://www.achimbo.de", | |
author:{name:"Achim Bode", email:"jo@achimbo.de"}, | |
license:"MIT", | |
version:".87", | |
takes: {"to (optional)": noun_arb_text}, | |
description:"You read a Web Page and want to keep something in mind about it. Select some text (optional) and enter 'know (your idea)', e.g. 'know interesting Qubiquity-Script to remind things by documentation in a wiki'. The script finds the open Browser-Tab where you maintain your documentation (by a part of the page title, see help:pageTitleSequence, must already be in edit-mode) and pastes the thought including URL, page title and selected text into the editor of the wiki page (by ID of the textarea element, see help:editorTextAreaID). Based on the famous fyi Script by Mike Chambers (http://www.mikechambers.com/ubiquity/fyi/) and credits to Christian Sonne for his support (http://getsatisfaction.com/mozilla/topics/how_can_i_search_for_an_open_tab_in_ubiquity)", | |
help:"If text from the current page is selected, the command will paste the selected text and current url, the page title and the text entered into the console in the wiki. Please adapt the variables pageTitleSequence (some Sequence of text appering in every pagetitle of your wiki in edit mode) and editorTextAreaID (open a wiki page in edit mode, choose 'View - Page Source' in Firefox - you'll find it when you search for 'textarea' in the source code).", | |
pageTitleSequence: "Bearbeiten von Knowlet", | |
editorTextAreaID: "wpTextbox1", | |
preview: function( pblock, konsole ) | |
{ | |
//generate the preview | |
var h = "knowlet: <br/>"; | |
var ausgabe = this.createString( konsole ); | |
var ausgabe = this.objectToString( this.getTextAreaWithSelection() ); | |
//h += ausgabe; | |
pblock.innerHTML = h; | |
}, | |
getKnowletEditor: function() { | |
return this.getLastTabStartingWith( this.pageTitleSequence ).document.getElementById( this.editorTextAreaID ); | |
}, | |
getKnowletContent: function() { | |
return this.getKnowletEditor().value; | |
}, | |
pasteKnowlet: function( appendText ) { | |
this.getKnowletEditor().value = this.getKnowletContent() + appendText; | |
}, | |
getLastTabStartingWith: function( title ){ | |
var tab = Utils.tabs.search( title ); | |
var kompletterSeitenName = ""; | |
var gefunden = false; | |
//finde den letzten Seitennamen im Hash-Objekt, das von Utils.tabs.search( title ) | |
//zurückgegeben wurde (die Seitennamen stehen im prop-Enumerator/-Iterator): | |
for (prop in tab){ | |
kompletterSeitenName = prop; | |
gefunden = true; | |
} | |
if( !gefunden ) this.onNoKnowletOpen(); | |
var tab = Utils.tabs.get( kompletterSeitenName ); | |
return tab; | |
}, | |
onNoKnowletOpen: function() { | |
displayMessage("ACHTUNG: Kein Knowlet geöffnet"); | |
}, | |
// for debugging purposes only...: | |
objectToString:function( o ) | |
{ | |
var str = ""; | |
for (var prop in o) { | |
str += prop; //Property-Name anzeigen | |
//str += " = " + o[prop]; //Property-Inhalt anzeigen | |
str += " = " + typeof( o[prop] ); // Datentyp anzeigen | |
str += "<br/>"; // Zeilenumbruch hinzufügen (Listenansicht) | |
} | |
return str; | |
}, | |
scrollEditorToBottom:function() { | |
var ta = this.getKnowletEditor(); | |
if(ta && ta.createTextRange){ | |
rng=ta.createTextRange(); | |
rng.collapse(false); | |
rng.select(); | |
} | |
}, | |
createString: function( konsole ) { | |
var doc = this.getDocument(); | |
var sel = this.getSelection(); | |
var title = doc.title; | |
var url = doc.location.href; | |
var string = ""; | |
var eintrag = konsole.text; // konsole.text oder konsole.html verwenden? | |
if ( eintrag == sel ) eintrag = ""; // wenn identisch mit Selektion, dann weglassen | |
// Wenn nicht leer ("") 2 Returns einfügen (bei "" kommen danach ohnehin 2 Zeilenumbüche) | |
// alle Backslash-n \n durch echte Linefeeds ersetzen | |
if ( eintrag != "" ) { //wenn Eintrag Konsole, dann Eintrag fett... | |
var semikolon = ( eintrag.charAt(0) != "=" ) ? ";" : ""; // Semikolon wird nur gesetzt, wenn keine Überschrift | |
string = "\n\n" + semikolon + eintrag.replace(/\\n/g, "\u000a") + "\n\n" + title + "\n\n" + ":" + url; | |
// bereits im String enthaltene Linefeeds müssen ersetzt werden, sonst werden sie "woertlich" ausgegeben | |
} else { // sonst Seitentitel fett drucken (;) | |
string = "\n\n;" + title + "\n\n" + ":" + url; | |
} | |
if ( sel != "" ) string += "\n\n<pre>" + sel + "</pre>"; //Zitat wird als preformatted ausgegeben | |
return string; | |
}, | |
execute: function( konsole ) | |
{ | |
this.pasteKnowlet( this.createString( konsole ) ); | |
//displayMessage( this.createString( konsole ) ); | |
}, | |
getDocument:function() | |
{ | |
return CmdUtils.getDocumentInsecure(); | |
}, | |
getSelection:function() | |
{ | |
return context.focusedWindow.getSelection(); | |
}, | |
getTextAreaWithSelection:function(){ | |
var textareas = document.getElementsByTagName("textarea"); | |
return textareas[0]; | |
/*for (var i=0; i < textareas.length; i++) { | |
}*/ | |
}, | |
getTextAreaSelection:function() | |
{ | |
var endpos = element.selectionEnd; | |
var startpos = element.selectionStart; | |
return; | |
}, | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment