diff --git a/dom2markdown/script.user.js b/dom2markdown/script.user.js index 776fb8e..41dd4ea 100644 --- a/dom2markdown/script.user.js +++ b/dom2markdown/script.user.js @@ -667,13 +667,18 @@ OL.prototype.bullet = function () { function LI (root, parent, dom) { Node.call(this, root, parent, dom) - this.list.items.push(this) + + if (this.list) { + this.list.items.push(this) + } } LI.prototype.__proto__ = Node.prototype NODES.LI = LI LI.prototype.compile = function () { + if (!this.list) return + var lines = this.lines.slice(0) , first = lines.shift() , line, last diff --git a/download_youtube_caption/script.user.js b/download_youtube_caption/script.user.js index 00ad363..1b2aa90 100644 --- a/download_youtube_caption/script.user.js +++ b/download_youtube_caption/script.user.js @@ -3,14 +3,16 @@ // @namespace http://userscripts.org/users/tim // @include http://*youtube.com/watch* // @include https://*youtube.com/watch* -// @require http://updater.usotools.co.cc/50003.js // @author Tim Smart -// @copyright 2009 Tim Smart +// @copyright 2009 Tim Smart; 2011 gw111zz // @license GNU GPL v3.0 or later. http://www.gnu.org/copyleft/gpl.html // ==/UserScript== -var PLAYER = unsafeWindow.document.getElementById('movie_player'), - VIDEO_ID = unsafeWindow.yt.getConfig('VIDEO_ID'), +var PLAYER = unsafeWindow.document.getElementById('movie_player'), + VIDEO_ID = unsafeWindow.yt.getConfig('VIDEO_ID'), + TITLE = unsafeWindow.ytplayer.config.args.title, + FORMATS = {srt: '.srt', text: 'text'}, + FORMAT_SELECTOR_ID = 'format_selector', caption_array = []; var makeTimeline = function (time) { @@ -35,7 +37,7 @@ var makeTimeline = function (time) { } return time_array.join(":") + "," + milliseconds; -}; +} function loadCaption (selector) { var caption = caption_array[selector.selectedIndex - 1]; @@ -49,9 +51,10 @@ function loadCaption (selector) { onload:function(xhr) { if (xhr.responseText !== "") { var caption, previous_start, start, end, - captions = new DOMParser().parseFromString(xhr.responseText, "text/xml").getElementsByTagName('text'), - textarea = document.createElement("textarea"), - srt_output = ''; + captions = new DOMParser().parseFromString(xhr.responseText, "text/xml").getElementsByTagName('text'), + textarea = document.createElement("textarea"), + output_format = FORMATS[document.getElementById(FORMAT_SELECTOR_ID).value] || FORMATS['srt'], + srt_output = ''; for (var i = 0, il = captions.length; i < il; i++) { caption = captions[i]; @@ -60,8 +63,12 @@ function loadCaption (selector) { if (0 <= previous_start) { textarea.innerHTML = captions[i - 1].textContent.replace(//g, ">" ); - srt_output += i + "\n" + makeTimeline(previous_start) + ' --> ' + - makeTimeline(start) + "\n" + textarea.value + "\n\n"; + if (output_format === FORMATS['text']) { + srt_output += textarea.value + "\n"; + } else { + srt_output += (i + 1) + "\n" + makeTimeline(previous_start) + ' --> ' + + makeTimeline(start) + "\n" + textarea.value + "\n\n"; + } previous_start = null; } @@ -76,9 +83,14 @@ function loadCaption (selector) { } textarea.innerHTML = caption.textContent.replace(//g, ">"); - srt_output += i + "\n" + makeTimeline(start) + ' --> ' + - makeTimeline(end) + "\n" + textarea.value + "\n\n"; - }; + if (output_format === FORMATS['text']) { + srt_output += textarea.value + "\n"; + } else { + srt_output += (i + 1) + "\n" + makeTimeline(start) + ' --> ' + + makeTimeline(end) + "\n" + textarea.value + "\n\n"; + } + } + textarea = null; GM_openInTab("data:text/plain;charset=utf-8," + encodeURIComponent(srt_output)); @@ -87,6 +99,7 @@ function loadCaption (selector) { } selector.options[0].selected = true; + } }); } @@ -96,13 +109,14 @@ function loadCaptions (select) { method: 'GET', url: 'http://video.google.com/timedtext?hl=en&v=' + VIDEO_ID + '&type=list', onload: function( xhr ) { - if (xhr.responseText === "") { - return select.options[0].textContent = 'No captions.'; - } var caption, option, caption_info, captions = new DOMParser().parseFromString(xhr.responseText, "text/xml"). getElementsByTagName('track'); + + if (captions.length === 0) { + return select.options[0].textContent = 'No captions.'; + } for (var i = 0, il = captions.length; i < il; i++) { caption = captions[i]; @@ -117,7 +131,7 @@ function loadCaptions (select) { option.textContent = caption_info.lang_name; select.appendChild(option); - }; + } select.options[0].textContent = 'Download captions.'; select.disabled = false; @@ -125,11 +139,26 @@ function loadCaptions (select) { }); } +function loadFormats (select) { + var type + + for (type in FORMATS) { + option = document.createElement('option'); + option.value = type; + option.textContent = FORMATS[type]; + + select.appendChild(option); + } + + select.options[0].textContent = 'Select caption format.'; + select.disabled = false; +} + (function () { var div = document.createElement('div'), select = document.createElement('select'), option = document.createElement('option'), - controls = document.getElementById('watch-headline-user-info'); + controls = document.getElementById('watch7-headline'); div.setAttribute( 'style', 'display: inline-block;' ); @@ -145,7 +174,28 @@ function loadCaptions (select) { }, false); div.appendChild(select); + + + var format_div = document.createElement('div'), + format_select = document.createElement('select'), + format_option = document.createElement('option'); + + format_div.setAttribute('style', 'display: inline-block;'); + + format_select.id = FORMAT_SELECTOR_ID; + format_select.disabled = true; + + format_option.textContent = 'Loading...'; + format_option.selected = true; + + format_select.appendChild(format_option); + + format_div.appendChild(format_select); + + controls.appendChild(format_div); controls.appendChild(div); + loadFormats(format_select); loadCaptions(select); })(); + diff --git a/gmail_auto_expand/script.user.js b/gmail_auto_expand/script.user.js index c00688b..c665ee9 100644 --- a/gmail_auto_expand/script.user.js +++ b/gmail_auto_expand/script.user.js @@ -4,7 +4,6 @@ // @description Expand conversations automatically // @include http://mail.google.com* // @include https://mail.google.com* -// @require http://updater.usotools.co.cc/37943.js // @require http://userscripts.org/scripts/source/56812.user.js // ==/UserScript== diff --git a/gmail_inbox_reply/script.user.js b/gmail_inbox_reply/script.user.js index f55c06c..bbe994f 100644 --- a/gmail_inbox_reply/script.user.js +++ b/gmail_inbox_reply/script.user.js @@ -3,7 +3,6 @@ // @namespace http://userscripts.org/users/63868 // @include http://mail.google.com* // @include https://mail.google.com* -// @require http://updater.usotools.co.cc/38212.js // @require http://userscripts.org/scripts/source/56812.user.js // ==/UserScript== diff --git a/gmail_next_conv/script.user.js b/gmail_next_conv/script.user.js index cef0fda..50a7fd3 100644 --- a/gmail_next_conv/script.user.js +++ b/gmail_next_conv/script.user.js @@ -4,7 +4,6 @@ // @description Instead of returning to the Inbox after archiving or deleting a conversation, you switch to the next one in line. // @include http://mail.google.com* // @include https://mail.google.com* -// @require http://updater.usotools.co.cc/37986.js // @require http://userscripts.org/scripts/source/56812.user.js // ==/UserScript== diff --git a/gmail_show_details/script.user.js b/gmail_show_details/script.user.js index f7c8d2a..276763c 100644 --- a/gmail_show_details/script.user.js +++ b/gmail_show_details/script.user.js @@ -5,7 +5,6 @@ // @include http://mail.google.com/* // @include https://mail.google.com/* // @require http://userscripts.org/scripts/source/56812.user.js -// @require http://updater.usotools.co.cc/57495.js // ==/UserScript== // Initialise the GMailAPI @@ -13,14 +12,14 @@ var api = new USO.Gmail() api.on('view:cv', function () { var view = this.view - , links = view.ownerDocument.evaluate - ( './/span[contains(., "show details")]' + var links = view.ownerDocument.evaluate( + './/span[contains(., "show details")]' , view , null , XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE , null ) - , link + var link = null for (var i = 0; i < links.snapshotLength; i++) { link = links.snapshotItem(i) diff --git a/gmail_show_images/script.user.js b/gmail_show_images/script.user.js index 2f84865..94b199f 100644 --- a/gmail_show_images/script.user.js +++ b/gmail_show_images/script.user.js @@ -3,7 +3,6 @@ // @namespace http://userscripts.org/users/tim // @include https://mail.google.com* // @include http://mail.google.com* -// @require http://updater.usotools.co.cc/51694.js // @require http://userscripts.org/scripts/source/56812.user.js // ==/UserScript== diff --git a/soundcloud_disable_comments/script.user.js b/soundcloud_disable_comments/script.user.js new file mode 100644 index 0000000..9d82c6e --- /dev/null +++ b/soundcloud_disable_comments/script.user.js @@ -0,0 +1,85 @@ +// ==UserScript== +// @name Soundcloud Disable Comments +// @description Remove comment elements from Soundcloud waveforms. +// @namespace http://userscripts.org/users/tim +// @include http://soundcloud.com/* +// @include https://soundcloud.com/* +// @copyright 2012 Tim Smart +// @license MIT. Full license in source code. +// ==/UserScript== + +// The MIT License +// +// Copyright (c) 2012 Tim Smart +// +// 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. + +;(function () { + +// For multiple environments. +var unsafe = unsafeWindow || window +// Find a MutationObserver constructor. +var MutationObserver = unsafe.MutationObserver + +if (!MutationObserver && unsafe.WebKitMutationObserver) { + MutationObserver = unsafe.WebKitMutationObserver +} + +// ==== +// Remove comments when found + +function removeComments () { + var commentBubbles = document.querySelectorAll('div.commentBubble') + var commentPlaceholders = document.querySelectorAll('div.commentPlaceholder') + var commentForms = document.querySelectorAll('div.commentForm') + var wrappers = document.querySelectorAll('div.waveform__scene') + var canvases = null + var element = null + + for (var i = 0, il = commentBubbles.length; i < il; i++) { + element = commentBubbles[i] + element.parentNode.removeChild(element) + } + for (var i = 0, il = commentPlaceholders.length; i < il; i++) { + element = commentPlaceholders[i] + element.parentNode.removeChild(element) + } + for (var i = 0, il = commentForms.length; i < il; i++) { + element = commentForms[i] + element.parentNode.removeChild(element) + } + for (var i = 0, il = wrappers.length; i < il; i++) { + element = wrappers[i] + canvases = element.querySelectorAll('canvas') + + if (3 === canvases.length) { + element = canvases[1] + element.parentNode.removeChild(element) + } + } +} + +var observer = new MutationObserver(removeComments) +observer.observe(document, { childList : true, subtree : true }) +removeComments() + +})(); + +/* vim: set expandtab sts=2 ts=2 sw=2 tw=80 ft=javascript :*/ diff --git a/uso_custom_search/script.user.js b/uso_custom_search/script.user.js index b800792..31a4942 100644 --- a/uso_custom_search/script.user.js +++ b/uso_custom_search/script.user.js @@ -5,7 +5,6 @@ // @author Tim Smart // @copyright 2010 (c) Tim Smart. All rights reserved. // @license Creative Commons BY-NC-SA http://creativecommons.org/licenses/by-nc-sa/3.0/ -// @require http://updater.usotools.co.cc/88396.js // ==/UserScript== var CONFIG = { diff --git a/uso_gmail/script.user.js b/uso_gmail/script.user.js index 3dbf092..de44e6d 100644 --- a/uso_gmail/script.user.js +++ b/uso_gmail/script.user.js @@ -34,13 +34,23 @@ if (typeof USO !== 'object') { var G = USO.Gmail = function Gmail (options) { options || (options = {}) - this.window = unsafeWindow || window - this.api = null - this.version = options.version || 2 - this._events = {} - this.loaded = false + this.window = unsafeWindow || window + this.canvas_win = null + this.canvas_doc = null + this.api = null + this.version = options.version || 2 + this._events = {} + this.loaded = false + this._Observer = null + this._observers = + { loading : null + , compose : null + } + this.cache = + { composers : [] + } - var gmail = this + var gmail = this try { if ( this.window.gmonkey @@ -56,15 +66,59 @@ if (typeof USO !== 'object') { this.emit('error', err) } + function updateElements () { + if (null === gmail.compose_wrap) return + + gmail._observers.loading.disconnect() + gmail.loaded = true + gmail.emit('loaded', gmail.api) + + gmail._observers.compose = new gmail._Observer(composeObserver) + gmail._observers.compose.observe( + gmail.compose_wrap + , { childList : true, subtree : true } + ) + } + + function composeObserver () { + if (!gmail.is_composing) { + for (var i = 0, il = gmail.cache.composers.length; i < il; i++) { + gmail.emit('compose:closed', gmail.cache.composers[i]) + } + gmail.cache.composers = [] + + return + } + + var composers = gmail.compose_wrap.querySelectorAll('div.nH.nn > div.no') + composers.__proto__ = Array.prototype + + var oldcomposers = gmail.cache.composers + var compose = null + + for (var i = 0, il = composers.length; i < il; i++) { + composer = composers[i] + if (-1 === oldcomposers.indexOf(composer)) { + gmail.emit('compose', composer) + } + } + + for (var i = 0, il = oldcomposers.length; i < il; i++) { + composer = oldcomposers[i] + if (-1 === composers.indexOf(composer)) { + gmail.emit('compose:closed', composer) + } + } + + gmail.cache.composers = composers + } + this.on('loaded:api', function () { this.api.registerViewChangeCallback(function () { var view = gmail.view_type if (!view) { return - } else if (!gmail.loaded) { - gmail.loaded = true - gmail.emit('loaded', gmail.api) } gmail.emit('view', view) @@ -95,6 +149,21 @@ if (typeof USO !== 'object') { this.api.registerThreadViewChangeCallback(function (thread) { gmail.emit('thread:view', thread) }) + + this.canvas_doc = this.canvas.ownerDocument + this.canvas_win = this.canvas_doc.defaultView + + if (this.canvas_win.MutationObserver) { + this._Observer = this.canvas_win.MutationObserver + } else if (this.canvas_win.WebKitMutationObserver) { + this._Observer = this.canvas_win.WebKitMutationObserver + } + + this._observers.loading = new this._Observer(updateElements) + this._observers.loading.observe( + this.canvas_doc.body + , { childList : true, subtree : true } + ) }) } @@ -146,6 +215,19 @@ if (typeof USO !== 'object') { return this } + G.prototype.__defineGetter__('compose_wrap', function () { + if (this.cache.compose_wrap) return this.cache.compose_wrap + + var wrap = this.canvas_doc.querySelector('body > div.dw') + this.cache.compose_wrap = wrap + + return this.cache.compose_wrap + }) + + G.prototype.__defineGetter__('is_composing', function () { + return !this.hasClass(this.compose_wrap, 'np') + }) + G.prototype.__defineGetter__('info', function () { return this.window.gmonkey.info(this.version) }) @@ -155,7 +237,9 @@ if (typeof USO !== 'object') { }) G.prototype.__defineGetter__('canvas', function () { - return this.api.getCanvasElement() + if (this.cache.canvas) return this.cache.canvas + this.cache.canvas = this.api.getCanvasElement() + return this.cache.canvas }) G.prototype.__defineGetter__('view', function () { @@ -194,7 +278,7 @@ if (typeof USO !== 'object') { return this.api.getActionElements() }) - G.prototype.__defineGetter__('converstation_diabled', function () { + G.prototype.__defineGetter__('converstation_disabled', function () { return this.api.isConversationViewDisabled() }) @@ -205,15 +289,19 @@ if (typeof USO !== 'object') { G.prototype.click = function (element) { var click = document.createEvent('MouseEvents') - click.initMouseEvent - ( 'click', true, true - , document.defaultView - , 1, 0, 0, 0, 0 - , false, false, false, false - , 0, null - ) + click.initMouseEvent( + 'click', true, true + , document.defaultView + , 1, 0, 0, 0, 0 + , false, false, false, false + , 0, null + ) element.dispatchEvent(click) return this } + + G.prototype.hasClass = function (element, classname) { + return element.classList.contains(classname) + } })(USO); diff --git a/uso_links/script.user.js b/uso_links/script.user.js index 4dd30aa..05f54a4 100644 --- a/uso_links/script.user.js +++ b/uso_links/script.user.js @@ -4,7 +4,6 @@ // @description Add's shortcuts links to the login status bar. // @include http://userscripts.org/* // @include https://userscripts.org/* -// @require http://updater.usotools.co.cc/105289.js // @license MIT (See file header) // @copyright (c) 2011 Tim Smart // ==/UserScript== @@ -60,16 +59,18 @@ function createLink (name, path) { } // Check for the /home link -var home = document.evaluate - ( './/ul[@class="login_status"]/li/a[@href="/home"]' - , document - , null - , XPathResult.FIRST_ORDERED_NODE_TYPE - , null - ) - .singleNodeValue - , first = true - , name, link +var home = document.evaluate( + './/ul[@class="login_status"]/li/a[@href="/home"]' +, document +, null +, XPathResult.FIRST_ORDERED_NODE_TYPE +, null +) + .singleNodeValue + +var first = true +var name = null +var link = null // The user is not logged in if (!home) { diff --git a/uso_meet_markdown/script.user.coffee b/uso_meet_markdown/script.user.coffee index 2233b02..948b997 100644 --- a/uso_meet_markdown/script.user.coffee +++ b/uso_meet_markdown/script.user.coffee @@ -7,7 +7,6 @@ # @namespace http://userscripts.org/users/tim # @description Markdown gets married to Userscript.org # @include http://userscripts.org/topics/* -# @require http://updater.usotools.co.cc/70901.js # @require http://userscripts.org/scripts/source/70908.user.js # @require http://userscripts.org/scripts/source/104570.user.js # ==/UserScript== @@ -38,12 +37,12 @@ class Post authorCont = @element.getElementsByClassName('author')[0] nameLink = authorCont.getElementsByClassName('fn')[0] .getElementsByTagName('a')[0] + useragent = authorCont.getElementsByClassName('useragent')[0] linkCont = authorCont.getElementsByTagName('p')[0] - if not linkCont + if not linkCont or useragent isnt linkCont.nextElementSibling linkCont = document.createElement 'p' - authorCont.insertBefore linkCont, - authorCont.getElementsByClassName('useragent')[0] + authorCont.insertBefore linkCont, useragent @id = /\d+$/.exec(@element.id)[0] @userId = nameLink.getAttribute 'user_id' @@ -60,12 +59,6 @@ class Post @insertUtility 'Quote', linkCont, => @quote() - # Insert the Report link, depending if the post - # belongs to the current user or not - if not @belongsToUser - @insertUtility 'Report', linkCont, (event) => - @report event - # Shortcut for inserting a utility link into the post # author section. cont is an optional container, to save # looking for it again @@ -127,30 +120,6 @@ class Post else html = @body page.editor.insertQuote html, @userName, @userId, @id - # This function will report the post as spam, to the USO spam topic - report: (event) -> - comments = prompt 'Do you want to mention any specific details about the offender?', - 'This post contained spam.' - - reportHtml = "
I believe the user #{@userName} has - made an inappropiate post - in the topic #{page.title}.
" - - if not comments - return - else if '' isnt comments - reportHtml += "#{comments}
" - - GM_xmlhttpRequest - url: "http://#{location.host}/topics/9/posts" - method: 'POST' - headers: - 'Content-Type': 'application/x-www-form-urlencoded' - data: "authenticity_token=#{encodeURIComponent unsafeWindow.auth_token}&post%5Bbody%5D=" + - "#{encodeURIComponent reportHtml}&commit=Post+reply" - onload: -> - event.target.textContent = 'Reported!' - #### Guide class # Represents a guide on Userscripts.org class Guide @@ -179,32 +148,13 @@ class Editor oldSetReplyId.apply unsafeWindow.EditForm, arguments @element = document.getElementById 'edit' - @modifyEntryContainer @element @textarea = document.getElementById 'edit_post_body' textarea = @textarea @addShortcuts @textarea - # Modify the submit button to convert the textarea - # content before sending it off to USO - @element.getElementsByTagName('form')[0]. - elements[3]. - addEventListener('click', -> - textarea.value = markdownToHtml textarea.value - , false) - @textarea.value = htmlToMarkdown @textarea.value - - # For the normal reply box - @modifyEntryContainer @element - - form = @element.getElementsByTagName('form')[0] textarea = document.getElementById 'post_body' - @element.getElementsByTagName('form')[0]. - elements[2]. - addEventListener('click', => - textarea.value = markdownToHtml textarea.value - , false) @addShortcuts textarea oldReplyInit = unsafeWindow.ReplyForm.init @@ -215,12 +165,6 @@ class Editor @element = null - # This function takes a reply 'containter' div, and chops and changes - # it to our liking - modifyEntryContainer: (element) -> - element.getElementsByTagName('h5')[1] - .textContent = 'Use Markdown to format your reply.' - # This function takes html, the User-Name, a User ID and a post ID, # converts it to markdown, then inserts the # resulting quote into the current textarea @@ -231,11 +175,12 @@ class Editor previous + html html = html.replace(//, '').trim() - html = "#{username}" + - " wrote:" + html = "
#{html}
" html = modify html if modify @textarea.value = htmlToMarkdown html + this # Insert text at the caret position insertAtCaret: (text) -> diff --git a/uso_meet_markdown/script.user.js b/uso_meet_markdown/script.user.js index 04a4cc2..7b4a254 100644 --- a/uso_meet_markdown/script.user.js +++ b/uso_meet_markdown/script.user.js @@ -1,37 +1,46 @@ +// USO, meet Markdown. One day Userscripts.org used plain HTML for writing comments and guides, +// little did he know about a young lass that called herself Markdown. +// Userscripts.org fell madly in love. + // ==UserScript== -// @name USO, meet Markdown. -// @namespace http://userscripts.org/users/tim -// @description Markdown gets married to Userscript.org -// @include http://userscripts.org/topics/* -// @require http://updater.usotools.co.cc/70901.js -// @require http://userscripts.org/scripts/source/70908.user.js -// @require http://userscripts.org/scripts/source/104570.user.js +// @name USO, meet Markdown. +// @namespace http://userscripts.org/users/tim +// @description Markdown gets married to Userscript.org +// @include http://userscripts.org/topics/* +// @require http://userscripts.org/scripts/source/70908.user.js +// @require http://userscripts.org/scripts/source/104570.user.js // ==/UserScript== +// Some ideas in this script originated from SizzleMcTwizzle's comment fix script: +// http://userscripts.org/scripts/show/24464 +// +// Kudos to him! + // The MIT License +// Copyright (c) 2011 Tim Smart and friends. // -// Copyright (c) 2011 Tim Smart -// -// 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: +// 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 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. +// 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. +// Generated by CoffeeScript 1.6.3 var Editor, Guide, Page, Post, htmlToMarkdown, markdownToHtml, page, showdown; -var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + Post = (function() { function Post(page, element) { this.page = page; @@ -42,15 +51,19 @@ Post = (function() { this.initFromGuide(); } } + Post.prototype.element = null; + Post.prototype.initFromTopic = function() { - var authorCont, linkCont, nameLink; + var authorCont, linkCont, nameLink, useragent, + _this = this; authorCont = this.element.getElementsByClassName('author')[0]; nameLink = authorCont.getElementsByClassName('fn')[0].getElementsByTagName('a')[0]; + useragent = authorCont.getElementsByClassName('useragent')[0]; linkCont = authorCont.getElementsByTagName('p')[0]; - if (!linkCont) { + if (!linkCont || useragent !== linkCont.nextElementSibling) { linkCont = document.createElement('p'); - authorCont.insertBefore(linkCont, authorCont.getElementsByClassName('useragent')[0]); + authorCont.insertBefore(linkCont, useragent); } this.id = /\d+$/.exec(this.element.id)[0]; this.userId = nameLink.getAttribute('user_id'); @@ -58,15 +71,11 @@ Post = (function() { this.userHref = nameLink.href; this.body = this.element.getElementsByClassName('body')[0].innerHTML; this.belongsToUser = authorCont.getElementsByClassName('edit')[0] ? true : false; - this.insertUtility('Quote', linkCont, __bind(function() { - return this.quote(); - }, this)); - if (!this.belongsToUser) { - return this.insertUtility('Report', linkCont, __bind(function(event) { - return this.report(event); - }, this)); - } + return this.insertUtility('Quote', linkCont, function() { + return _this.quote(); + }); }; + Post.prototype.insertUtility = function(name, cont, callback) { var link, span; if ('function' === typeof cont) { @@ -92,6 +101,7 @@ Post = (function() { return cont.appendChild(span); } }; + Post.prototype.quote = function() { var element, fragment, holder, html, properSelection, range, selection; selection = window.getSelection(); @@ -123,35 +133,20 @@ Post = (function() { } return page.editor.insertQuote(html, this.userName, this.userId, this.id); }; - Post.prototype.report = function(event) { - var comments, reportHtml; - comments = prompt('Do you want to mention any specific details about the offender?', 'This post contained spam.'); - reportHtml = "#{username}" + + " wrote:
#{html}
I believe the user " + this.userName + " has made an inappropiate post in the topic " + page.title + ".
"; - if (!comments) { - return; - } else if ('' !== comments) { - reportHtml += "" + comments + "
"; - } - return GM_xmlhttpRequest({ - url: "http://" + location.host + "/topics/9/posts", - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - }, - data: ("authenticity_token=" + (encodeURIComponent(unsafeWindow.auth_token)) + "&post%5Bbody%5D=") + ("" + (encodeURIComponent(reportHtml)) + "&commit=Post+reply"), - onload: function() { - return event.target.textContent = 'Reported!'; - } - }); - }; + return Post; + })(); + Guide = (function() { function Guide(page, element) { this.page = page; } + return Guide; + })(); + Editor = (function() { function Editor(page, element) { this.page = page; @@ -160,41 +155,32 @@ Editor = (function() { this.initFromReply(); } } + Editor.prototype.element = null; + Editor.prototype.initFromReply = function() { - var form, oldReplyInit, oldSetReplyId, textarea; + var oldReplyInit, oldSetReplyId, textarea, + _this = this; oldSetReplyId = unsafeWindow.EditForm.setReplyId; - unsafeWindow.EditForm.setReplyId = __bind(function() { + unsafeWindow.EditForm.setReplyId = function() { var textarea; oldSetReplyId.apply(unsafeWindow.EditForm, arguments); - this.element = document.getElementById('edit'); - this.modifyEntryContainer(this.element); - this.textarea = document.getElementById('edit_post_body'); - textarea = this.textarea; - this.addShortcuts(this.textarea); - this.element.getElementsByTagName('form')[0].elements[3].addEventListener('click', function() { - return textarea.value = markdownToHtml(textarea.value); - }, false); - return this.textarea.value = htmlToMarkdown(this.textarea.value); - }, this); - this.modifyEntryContainer(this.element); - form = this.element.getElementsByTagName('form')[0]; + _this.element = document.getElementById('edit'); + _this.textarea = document.getElementById('edit_post_body'); + textarea = _this.textarea; + return _this.addShortcuts(_this.textarea); + }; textarea = document.getElementById('post_body'); - this.element.getElementsByTagName('form')[0].elements[2].addEventListener('click', __bind(function() { - return textarea.value = markdownToHtml(textarea.value); - }, this), false); this.addShortcuts(textarea); oldReplyInit = unsafeWindow.ReplyForm.init; - unsafeWindow.ReplyForm.init = __bind(function() { + unsafeWindow.ReplyForm.init = function() { oldReplyInit.call(unsafeWindow.ReplyForm); - this.element = document.getElementById('reply'); - return this.textarea = document.getElementById('post_body'); - }, this); + _this.element = document.getElementById('reply'); + return _this.textarea = document.getElementById('post_body'); + }; return this.element = null; }; - Editor.prototype.modifyEntryContainer = function(element) { - return element.getElementsByTagName('h5')[1].textContent = 'Use Markdown to format your reply.'; - }; + Editor.prototype.insertQuote = function(html, username, userId, postId) { var modify, previous; if (this.ensureElement()) { @@ -204,12 +190,14 @@ Editor = (function() { }; } html = html.replace(//, '').trim(); - html = ("" + username + "") + (" wrote:"); + html = ("
" + html + "
"); if (modify) { html = modify(html); } - return this.textarea.value = htmlToMarkdown(html); + this.textarea.value = htmlToMarkdown(html); + return this; }; + Editor.prototype.insertAtCaret = function(text) { var end, start; start = this.textarea.selectionStart; @@ -220,6 +208,7 @@ Editor = (function() { this.insertText(text, start, end); return this; }; + Editor.prototype.insertText = function(text, start, end) { var pos, val; end || (end = start); @@ -232,6 +221,7 @@ Editor = (function() { } return this; }; + Editor.prototype.ensureElement = function() { if (!this.element) { this.openReply(); @@ -243,9 +233,11 @@ Editor = (function() { return true; } }; + Editor.prototype.openReply = function() { return unsafeWindow.ReplyForm.init(); }; + Editor.prototype.addShortcuts = function(textarea) { var editor; editor = this; @@ -260,6 +252,7 @@ Editor = (function() { } }, false); }; + Editor.prototype.newline = function() { var indent, last_line, pos; pos = this.textarea.selectionStart; @@ -270,10 +263,14 @@ Editor = (function() { indent = /^(?:\s|>)*/.exec(this.textarea.value.slice(last_line + 1, pos)); return this.insertAtCaret('\n' + indent); }; + return Editor; + })(); + Page = (function() { function Page() {} + Page.prototype.init = function() { var path; path = location.pathname; @@ -281,9 +278,13 @@ Page = (function() { return this.initFromTopic(); } }; + Page.prototype.comments = []; + Page.prototype.editor = null; + Page.prototype.title = document.title; + Page.prototype.initFromTopic = function() { var post, postElements, _i, _len; postElements = document.getElementsByClassName('post'); @@ -294,17 +295,24 @@ Page = (function() { } return this.title = document.getElementById('topic-title').firstChild.textContent.trim().replace(/\s+/g, ' '); }; + return Page; + })(); + showdown = new Showdown.converter(); + htmlToMarkdown = function(html, callback) { var div; div = document.createElement('div'); div.innerHTML = html; return USO.dom2markdown(div); }; + markdownToHtml = function(markdown) { return showdown.makeHtml(markdown); }; + page = new Page(); + page.init();" + username + "") + (" wrote:
" + html + "