My day 2010-10-07

Today i made a greasmonkey -script for putting shared notes on websites.
One persson can add a note to a webpage they visiting, when that persson or
someone else in the same sharing-group visit that website, the note will apear.

// ==UserScript==
// @name					 url_notes
// @namespace			url_notes
// @description		keep notes on urls
// ==/UserScript==

var category = GM_getValue('url_note_category', '');

if(!category)
{
	change_category();
	category = GM_getValue('url_note_category', 'test');
}

function change_category()
{
	category = prompt("Välj en kategori/grupp", GM_getValue('url_note_category', ''));
	GM_setValue('url_note_category', category);
}

GM_registerMenuCommand("Change note category", change_category);
GM_registerMenuCommand("Add a note to this page", add_note);

get_notes(category, document.location.href, false);

function add_note()
{
	var category = GM_getValue('url_note_category', 'test');
	get_notes(category, document.location.href, true);
}

function get_notes(category, url, force)
{
	GM_xmlhttpRequest(
	{
		method: "POST",
		url: "https://www.exemple.se/url_notes.php",
		data: "category=" + urlencode(category) + "&url=" + urlencode(url) + "&",
		headers:
		{
			"Content-Type": "application/x-www-form-urlencoded"
		},
		onload: function(response)
		{
			var text = "";
			text += "<div style='float: right; cursor: pointer;' onclick=\"document.getElementById('note_box_div').parentNode.removeChild(document.getElementById('note_box_div'))\"><b>X</b></div>";
			text += "<div onmousedown='dragStart(event, \"note_box_div\")' style='background-color: orange; height: 15px;'>Antekningar</div>";
			if(response.responseText.length > 2)
			{
				var notes = eval("(" + response.responseText + ")");
				for(key in notes)
				{
					text += notes[key]['note'] + " <br /> /" + notes[key]['author'] + "<br/> " + notes[key]['birth'] + "<br /><hr />";
				}
				force = true;
			}
			if(force)
			{
				text += "<form action='https://www.exemple.se/url_notes.php' method='post'>";
				text += "<textarea name='note'></textarea><br/>";
				text += "<input type='submit' value='spara'/>";
				text += "<input type='hidden' name='url' value='" + urlencode(url) + "'/>";
				text += "<input type='hidden' name='category' value='" + urlencode(category) + "'/>";
				text += "</form>";
				var notes_div = document.createElement('div');
				notes_div.setAttribute('style', 'position: absolute; left: ' + (document.body.clientWidth -350) + 'px; right: auto; top: 100px; bottom: auto; width: 300px; height: auto; background-color: yellow; border: solid black 3px;');
				notes_div.innerHTML = text;
				notes_div.id = 'note_box_div';
				document.getElementsByTagName('body')[0].appendChild(notes_div);
				var dyn_script = document.createElement('script');
				dyn_script.src = "https://www.interfaceways.se/src/js/dynamic_boxes.js";
				document.getElementsByTagName('body')[0].appendChild(dyn_script);
			}
		}
	});
}

function urlencode(str)
{
	 return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}

Written by Puggan, 2010-10-07 19:10:11 CEST (+0200)

One response to “My day 2010-10-07”

Leave a Reply

Your email address will not be published. Required fields are marked *


line 13 column 94 - Warning: unescaped & which should be written as &amp;
line 13 column 95 - Warning: unescaped & or unknown entity "&h.getContext"
line 13 column 308 - Warning: unescaped & which should be written as &amp;
line 13 column 309 - Warning: unescaped & which should be written as &amp;
line 13 column 1373 - Warning: unescaped & which should be written as &amp;
line 13 column 1374 - Warning: unescaped & or unknown entity "&c.supports"
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1405 - Warning: unescaped & which should be written as &amp;
line 13 column 1406 - Warning: unescaped & which should be written as &amp;
line 13 column 1471 - Warning: unescaped & which should be written as &amp;
line 13 column 1472 - Warning: unescaped & or unknown entity "&c.supports"
line 13 column 1554 - Warning: unescaped & which should be written as &amp;
line 13 column 1555 - Warning: unescaped & which should be written as &amp;
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1291 - Warning: <i.length> unexpected or duplicate quote mark
line 13 column 1880 - Warning: unescaped & which should be written as &amp;
line 13 column 1881 - Warning: unescaped & or unknown entity "&c.readyCallback"
line 13 column 1958 - Warning: unescaped & which should be written as &amp;
line 13 column 1959 - Warning: unescaped & or unknown entity "&f.twemoji"
line 13 column 1969 - Warning: unescaped & which should be written as &amp;
line 13 column 1970 - Warning: unescaped & which should be written as &amp;
line 13 column 1291 - Warning: <i.length> attribute name "h++)c.supports[i[h]]" (value="d(i[h]),c.supports.everything=c.supports.everything&&c.supports[i[h]],"flag"!==i[h]&&(c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&c.supports[i[h]]);c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&!c.supports.flag,c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.everything||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);") is invalid
line 13 column 1291 - Warning: <i.length> missing '>' for end of tag
line 14 column 5 - Error: unexpected </script> in <i.length>
line 61 column 3 - Error: unexpected </head> in <i.length>
line 235 column 1 - Error: unexpected </html> in <i.length>