Add rainbow support.

This commit is contained in:
Black Hat 2018-07-11 16:07:04 +08:00
parent 65ff905a7c
commit afc901b017
2 changed files with 37 additions and 29 deletions

View File

@ -193,36 +193,42 @@ Item {
return return
} }
var type = "m.text"
var PREFIX_ME = '/me ' var PREFIX_ME = '/me '
var PREFIX_RAINBOW = '/rainbow' var PREFIX_RAINBOW = '/rainbow '
var PREFIX_HTML = '/html '
var PREFIX_MARKDOWN = '/md '
if (text.indexOf(PREFIX_ME) === 0) { if (text.indexOf(PREFIX_ME) === 0) {
text = text.substr(PREFIX_ME.length) text = text.substr(PREFIX_ME.length)
type = "m.emote" currentRoom.postMessage("m.emote", text)
return
} }
if (text.indexOf(PREFIX_RAINBOW) === 0) { if (text.indexOf(PREFIX_RAINBOW) === 0) {
text = text.substr(PREFIX_RAINBOW.length) text = text.substr(PREFIX_RAINBOW.length)
var parsedText = ""
var rainbowColor = ["#ee0000", "#ff7700", "#eeee00", "#00bb00", "#0000ee", "#dd00dd", "#880088"]
for (var i = 0; i < text.length; i++) {
parsedText = parsedText + "<font color='" + rainbowColor[i % 7] + "'>" + text.charAt(i) + "</font>"
}
currentRoom.postHtmlMessage(text, parsedText, "m.text")
return
} }
if (text.indexOf(PREFIX_HTML) === 0) {
var result = parse(text) text = text.substr(PREFIX_HTML.length)
var parsedText = result[0] var re = new RegExp("<.*?>")
var isMarkdown = result [1] var plainText = text.replace(re, "")
currentRoom.postHtmlMessage(plainText, text, "m.text")
if (isMarkdown) currentRoom.postHtmlMessage(text, parsedText, type) return
else currentRoom.postMessage(type, text) }
} if (text.indexOf(PREFIX_MARKDOWN) === 0) {
text = text.substr(PREFIX_MARKDOWN.length)
function parse(text) {
if (!testHTML(text)) {
var parsedText = Markdown.markdown_parser(text) var parsedText = Markdown.markdown_parser(text)
if (testHTML(parsedText)) return [parsedText, true] currentRoom.postHtmlMessage(text, parsedText, "m.text")
return
} }
return [text, false]
}
function testHTML(text) { currentRoom.postMessage("m.text", text)
var re = new RegExp("(<([^>]+)>)")
return re.test(text)
} }
} }

View File

@ -28,16 +28,18 @@ ApplicationWindow {
property alias token: matriqueController.token property alias token: matriqueController.token
} }
// Platform.SystemTrayIcon { // Platform.SystemTrayIcon {
// visible: true // id: trayIcon
// iconSource: "qrc:/asset/img/icon.png"
// onActivated: { // visible: true
// window.show() // iconSource: "qrc:/asset/img/icon.png"
// window.raise()
// window.requestActivate() // onActivated: {
// } // window.show()
// } // window.raise()
// window.requestActivate()
// }
// }
Controller { Controller {
id: matriqueController id: matriqueController