Last active
January 27, 2016 14:55
-
-
Save petitviolet/eb1836eef8d72e736404 to your computer and use it in GitHub Desktop.
GreaseMonkey User Script for styling CNN Student News Transcript Web page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name CNN_StudentNews_Style | |
// @namespace petitviolet | |
// @include http://transcripts.cnn.com/TRANSCRIPTS/**/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
(function CnnStudentNewsStyle() { | |
console.log("modify style..."); | |
// body of transcript | |
var body = document.getElementsByClassName("cnnBodyText")[2]; | |
// start a new line after period(.) | |
var contents = body.innerHTML.replace(/\.\s/g, ".<br>"); | |
// extract speaker's name | |
var regex = /^\s*(.+?):(.*)$/g; | |
var brs = contents.split("<br>"); | |
var result_texts = []; | |
for (var i in brs) { | |
var result = regex.exec(brs[i]) | |
if (result != null) { | |
var name = result[1]; | |
var text = result[2]; | |
name = "<br><span style='color:#944'>" + name + ":</span><br>"; | |
result_texts.push(name + text); | |
} else if (result != ""){ | |
result_texts.push(brs[i]); | |
} | |
} | |
// remove too much <br> tags | |
body.innerHTML = result_texts.join("<br>").replace(/<br> <br>/g, "<br>"); | |
console.log("end!"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment