Skip to content

Instantly share code, notes, and snippets.

@think49
Created January 15, 2011 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save think49/781078 to your computer and use it in GitHub Desktop.
Save think49/781078 to your computer and use it in GitHub Desktop.
LingrRoomArchives-bookmarklet.js : Lingr の "room archives" でHTMLログを出力する bookmarklet
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Lingr room bookmarklet</title>
<style>
html { margin: 0; padding: 0; }
body { margin: 0; padding: 0; color: #555; background-color: #fdfdd1; }
h1, h2, h3, h4, h5, h6 { margin: 0; padding: 0; color: #CB7500; font-family: Georgia, Times, serif; text-shadow: #DDD 0px 0.05em 0.05em; }
h1 { margin: 0 0 1em; padding: 0.5em 1em; font-size: 2.5em; color: #fbf4eb; background-color: #e4851d; }
h2 { font-size: 2em; }
h3 { font-size: 1em; text-align: right; }
a { color: #0F5887; text-decoration: none; }
#LingrLog { margin: 0; padding: 0.7em; border: 1px solid #DDD; background-color: white; }
#LingrLog dt { margin: 0.5em 0 0; padding: 0; }
#LingrLog dd { margin: 0; padding: 0; }
#LingrLog pre { margin: 0; padding: 0; }
h2, h3, h4, h5, h6, p, #LingrLog { margin: 16px; }
.timestamp { color: #E1BB88; font-family: 'Gill Sans', Verdana, Arial, sans-serif; }
.text { color: #333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', sans-serif; line-height: 1.2; }
.nickname { color: #793B00; font-family: Helvetica, 'Trebuchet MS', sans-serif; }
</style>
</head>
<body>
<h1>Lingr</h1>
<h2>Bookmarklet</h2>
<p>Please carry out this bookmark let by "room archives".</p>
<ul>
<li><a href="javascript:(function(){var doc = document;var script = doc.createElement('script');script.type='text/javascript';script.src='http://vird2002.s8.xrea.com/javascript/LingrRoomArchives-bookmarklet.js';doc.getElementsByTagName('head')[0].appendChild(script);})();">ToLingrChatLog</a></li>
</ul>
<h2>Link</h2>
<ul>
<li><a href="https://gist.github.com/781078">gist: 781078 - Lingr-ChatRoomArchives.js - GitHub</a></li>
</ul>
</body>
</html>
/**
* LingrRoomArchives-bookmarklet.js
*
* @version 1.0.1
* @author think49
*/
(function () {
var doc, dt, dd, newlineNode, indentNode, logElement, h2, h3, infoElements, p, textarea;
doc = document;
logElement = doc.createElement('dl');
logElement.id = 'LingrLog';
indentNode = doc.createTextNode(' ');
newlineNode = doc.createTextNode('\r\n');
logElement.appendChild(newlineNode.cloneNode(false));
dt = doc.createElement('dt');
dt.appendChild(doc.createElement('a'));
dt.appendChild(doc.createTextNode(' '));
dt.appendChild(doc.createElement('span'));
dt.firstChild.className = 'nickname';
dt.firstChild.appendChild(doc.createTextNode(''));
dt.lastChild.className = 'timestamp';
dt.lastChild.appendChild(doc.createTextNode(''));
dd = doc.createElement('dd');
dd.appendChild(doc.createElement('pre'));
dd.firstChild.className = 'text';
dd.firstChild.appendChild(doc.createTextNode(''));
Array.prototype.forEach.call(doc.querySelectorAll('.message.user'), function (element) {
var doc, nickname;
doc = element.ownerDocument;
dt.firstChild.href = element.querySelector('.speaker').href;
dt.firstChild.firstChild.nodeValue = element.querySelector('.speaker > .nickname').firstChild.nodeValue;
dt.lastChild.firstChild.nodeValue = element.querySelector('.timestamp > .iso8601').firstChild.nodeValue;
dd.firstChild.firstChild.nodeValue = element.querySelector('.text > .original > pre').firstChild.nodeValue;
logElement.appendChild(indentNode.cloneNode(false));
logElement.appendChild(dt.cloneNode(true));
logElement.appendChild(newlineNode.cloneNode(false));
logElement.appendChild(indentNode.cloneNode(false));
logElement.appendChild(dd.cloneNode(true));
logElement.appendChild(newlineNode.cloneNode(false));
});
h2 = doc.createElement('h2');
h2.appendChild(doc.querySelector('#content>h2').firstChild.cloneNode(false));
infoElements = doc.querySelectorAll('#content>h4');
h3 = doc.createElement('h3');
h3.appendChild(doc.createTextNode(infoElements[0].firstChild.nodeValue + ' / ' + infoElements[1].firstChild.nodeValue));
textarea = doc.createElement('textarea');
textarea.style.display = 'block';
textarea.style.margin = '2em auto';
textarea.style.width = '80%';
textarea.style.height = '10em';
textarea.value = [h2.outerHTML, h3.outerHTML, logElement.outerHTML].join('\r\n');
p = doc.createElement('p');
p.appendChild(textarea);
doc.body.appendChild(p);
})();
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Lingr room log</title>
<style>
html { margin: 0; padding: 0; }
body { margin: 0; padding: 0; color: #555; background-color: #fdfdd1; }
h1, h2, h3, h4, h5, h6 { margin: 0; padding: 0; color: #CB7500; font-family: Georgia, Times, serif; text-shadow: #DDD 0px 0.05em 0.05em; }
h1 { margin: 0 0 1em; padding: 0.5em 1em; font-size: 2.5em; color: #fbf4eb; background-color: #e4851d; }
h2 { font-size: 2em; }
h3 { font-size: 1em; text-align: right; }
a { color: #0F5887; text-decoration: none; }
#LingrLog { margin: 0; padding: 0.7em; border: 1px solid #DDD; background-color: white; }
#LingrLog dt { margin: 0.5em 0 0; padding: 0; }
#LingrLog dd { margin: 0; padding: 0; }
#LingrLog pre { margin: 0; padding: 0; }
h2, h3, h4, h5, h6, p, #LingrLog { margin: 16px; }
.timestamp { color: #E1BB88; font-family: 'Gill Sans', Verdana, Arial, sans-serif; }
.text { color: #333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', sans-serif; line-height: 1.2; }
.nickname { color: #793B00; font-family: Helvetica, 'Trebuchet MS', sans-serif; }
</style>
</head>
<body>
<h1>Lingr</h1>
<!-- Paste makes the "chat log" here. -->
</body>
</html>
@think49
Copy link
Author

think49 commented Jan 15, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment