← Older revision | Revision as of 01:00, 29 April 2012 |
(One intermediate revision by one user not shown) |
Line 1: | Line 1: |
− | //alert("Testing..."); | + | //importScriptURI('http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js&action=raw&ctype=text/javascript'); |
| + | |
| + | //can I just use the wikibits importStylesheetURI()? |
| + | function popups_importStylesheetURI(url) { |
| + | return document.createStyleSheet ? document.createStyleSheet(url) : appendCSS('@import "' + url + '";'); |
| + | } |
| + | |
| + | popups_importStylesheetURI('http://en.wikipedia.org/w/index.php?action=raw&ctype=text/css&title=User:Lupin/navpopdev.css'); |
| + | importScriptURI('http://en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-popups.js&action=raw&ctype=text/javascript'); |
| + | |
| + | /* <pre> */ |
| + | |
| + | popupPreviewKillTemplates = false; |
| + | try |
| + | { |
| + | Previewmaker.prototype.firstBit = function () { |
| + | //Skip for main namespace only. |
| + | var wiktTitle = this.baseUrl.split('/wiki')[1]; |
| + | if (!wiktTitle) title = ''; |
| + | if (wiktTitle.search(':') != -1) { |
| + | // dont't be givin' me no subsequent paragraphs, you hear me? |
| + | /// first we "normalize" section headings, removing whitespace after, adding before |
| + | var d=this.data; |
| + | |
| + | if (getValueOf('popupPreviewCutHeadings')) { |
| + | this.data=this.data.replace(RegExp('\\s*(==+[^=]*==+)\\s*', 'g'), '\n\n$1 '); |
| + | /// then we want to get rid of paragraph breaks whose text ends badly |
| + | this.data=this.data.replace(RegExp('([:;]) *\\n{2,}', 'g'), '$1\n'); |
| + | |
| + | this.data=this.data.replace(RegExp('^[\\s\\n]*'), ''); |
| + | stuff=(RegExp('^([^\\n]|\\n[^\\n\\s])*')).exec(this.data); |
| + | if (stuff) { d = stuff[0]; } |
| + | if (!getValueOf('popupPreviewFirstParOnly')) { d = this.data; } |
| + | |
| + | /// now put \n\n after sections so that bullets and numbered lists work |
| + | d=d.replace(RegExp('(==+[^=]*==+)\\s*', 'g'), '$1\n\n'); |
| + | } |
| + | |
| + | // superfluous sentences are RIGHT OUT. |
| + | // note: exactly 1 set of parens here needed to make the slice work |
| + | d = d.parenSplit(RegExp('([!?.]+["'+"'"+']*\\s)','g')); |
| + | // leading space is bad, mmkay? |
| + | d[0]=d[0].replace(RegExp('^\\s*'), ''); |
| + | |
| + | var notSentenceEnds=RegExp('([^.][a-z][.][a-z]|etc|sic|Dr|Mr|Mrs|Ms|St|no|\\[[^\\]]*|\\s[A-Zvclm])$', 'i'); |
| + | |
| + | d = this.fixSentenceEnds(d, notSentenceEnds); |
| + | |
| + | var maxChars=getValueOf('popupMaxPreviewCharacters'); |
| + | var n=getValueOf('popupMaxPreviewSentences'); |
| + | var dd; |
| + | |
| + | do {dd=this.firstSentences(d,n); --n; } |
| + | while ( dd.length > maxChars && n > 0 ); |
| + | |
| + | this.data = dd; |
| + | |
| + | } else { |
| + | |
| + | //TODO: Limit this override to urls that start with http://*.wiktionary.org/ |
| + | //TODO: extend the above section to also preview Wikipedia links |
| + | |
| + | var d=this.data; |
| + | var charsWikt = 0; |
| + | |
| + | var linesWikt = d.split('\n'); |
| + | for (jWikt=0; jWikt<linesWikt.length; jWikt++) { |
| + | linesWikt[jWikt] = linesWikt[jWikt].replace(/\{\{[in]transitive}}/g, ''); |
| + | linesWikt[jWikt] = linesWikt[jWikt].replace(/\{\{[un]countable}}/g, ''); |
| + | linesWikt[jWikt] = linesWikt[jWikt].replace(/\{\{cattag\|(.*?)}}/g, ""); |
| + | linesWikt[jWikt] = linesWikt[jWikt].replace(/[\{\}]/g, "'"); |
| + | if (linesWikt[jWikt].search(/^[#]/) == -1) { |
| + | if (linesWikt[jWikt].search(/^==[A-Z]/) == -1) {linesWikt[jWikt] = '';} |
| + | } |
| + | charsWikt += linesWikt[jWikt].length; |
| + | } |
| + | if (charsWikt < 2) {linesWikt[0] = "No properly formatted content";} |
| + | |
| + | var maxChars=getValueOf('popupMaxPreviewCharacters'); |
| + | var n=getValueOf('popupMaxPreviewSentences'); |
| + | var dd=''; |
| + | |
| + | for (jWikt=0; jWikt<linesWikt.length; jWikt++) { |
| + | if (linesWikt[jWikt] != '') {dd += linesWikt[jWikt] + '\n';} |
| + | if (dd.length < maxChars) { this.data = dd; } |
| + | } |
| + | } |
| + | }; |
| + | } |
| + | catch(e) {} |