|
// ==UserScript== |
|
// @name HAL/JSON formatter + link |
|
// @version 2015.11.11 |
|
// @description Formats JSON objects, creates <A> elements of strings that look like URLs |
|
// @author Trygve Laugstøl <[email protected]> |
|
// @match http://localhost:8080/api/* |
|
// @match https://fiken.no/api/* |
|
// @require http://code.jquery.com/jquery-latest.js |
|
// @copyright 2015 |
|
// @url https://gist.githubusercontent.com/trygvis/6b0b336466dab822800f/raw/app.js |
|
// ==/UserScript== |
|
|
|
(function() { |
|
'use strict'; |
|
|
|
var $ = jQuery.noConflict(true); |
|
|
|
try { |
|
var pre = $('html > body > pre'); |
|
if (!pre.length == 1) { |
|
return; |
|
} |
|
|
|
var text = pre.text(); |
|
var j = JSON.parse(text); |
|
var text = JSON.stringify(j, undefined, 2); |
|
|
|
var message = $('<span></spam>'); |
|
message.attr('style', 'position: absolute; right: 0;'); |
|
|
|
var halBrowser = window.location.protocol + '//' + window.location.host + '/api/v1/browser.html#' + window.location.pathname; |
|
|
|
var a = $('<a>').attr('href', halBrowser).text('HAL Browser'); |
|
message.append(a); |
|
|
|
pre.parent().prepend(message); |
|
|
|
text = text.replace(/"(http.?:\/\/.*)"/g, '"<a href="$1">$1</a>"'); |
|
|
|
var x = $('<pre>' + text + '</pre>'); |
|
|
|
pre.replaceWith(x); |
|
} catch(e) { |
|
// ignore. this is probably not a JSON document |
|
} |
|
})(); |
|
|
|
/* |
|
The MIT License (MIT) |
|
|
|
Copyright (c) 2015 Trygve Laugstøl <[email protected]> |
|
|
|
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. |
|
*/ |