-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
311 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
'use strict'; | ||
|
||
const createElement = FrankerFaceZ.utilities.dom.createElement; | ||
const sanitize = FrankerFaceZ.utilities.dom.sanitize; | ||
|
||
import STYLE_RO from './styles.css'; | ||
|
||
class RagnarokDatabase extends Addon { | ||
constructor(...args) { | ||
super(...args); | ||
|
||
this.inject('chat'); | ||
this.settings.add('addon.rodb.server',{ | ||
default: 'iRO', | ||
ui: { | ||
path: 'Add-Ons > Ragnarok Database >> Server', | ||
title: 'Default Server', | ||
description:'Choose your default server where data should be displayed from. If the item doesn\'t exit on your server it will try iRO next and finally kRO.', | ||
component: 'setting-select-box', | ||
multiple: false, | ||
data: [ | ||
{ value: 'aRO', title: 'aRO' }, | ||
{ value: 'bRO', title: 'bRO' }, | ||
{ value: 'fRO', title: 'fRO' }, | ||
{ value: 'idRO', title: 'idRO' }, | ||
{ value: 'iRO', title: 'iRO' }, | ||
{ value: 'jRO', title: 'jRO' }, | ||
{ value: 'kROM', title: 'kROM' }, | ||
{ value: 'kROZ', title: 'kROZ' }, | ||
{ value: 'kROZS', title: 'kROZS' }, | ||
{ value: 'GGH', title: 'GGH' }, | ||
{ value: 'ropEU', title: 'ropEU' }, | ||
{ value: 'ropRU', title: 'ropRU' }, | ||
{ value: 'thROG', title: 'thROG' }, | ||
{ value: 'twRO', title: 'twRO' }, | ||
{ value: 'cRO', title: 'cRO' }, | ||
{ value: 'iROC', title: 'iROC' } | ||
] | ||
}, | ||
changed: (val) => { | ||
this.server = val; | ||
this.emit('chat:update-lines'); | ||
} | ||
}); | ||
|
||
var self = this; | ||
|
||
this.messageFilter = { | ||
type: 'rodb', | ||
priority: 9, | ||
|
||
render(token, createElement){ | ||
return ( | ||
<div class="dp-tooltip dp-tooltip-item"> | ||
<div class="dp-tooltip-head"> | ||
<h3><a href={token.url} target="_newFrame">{token.roname} ({token.roserver})</a></h3> | ||
</div> | ||
<div class="dp-tooltip-body"> | ||
<span class="dp-icon dp-icon-item dp-icon-item-large dp-icon-item-white"> | ||
<span class="icon-item-inner icon-item-default" style={{backgroundImage: 'url(https://static.divine-pride.net/images/items/collection/'+token.roid+'.png)'}}> | ||
</span> | ||
</span> | ||
<div class="dp-item-properties"> | ||
<ul> | ||
<li><font color="#000000" dangerouslySetInnerHTML={{ __html: token.description }}></font></li> | ||
</ul> | ||
<span class="clear"></span> | ||
</div> | ||
</div> | ||
<div class="dp-tooltip-foot"></div> | ||
</div>); | ||
}, | ||
|
||
process(tokens, msg) { | ||
var regex = /.*divine-pride.net\/database\/([a-z]+)\/([0-9]+).*/; | ||
for(const token of tokens) { | ||
if (token.type == 'link' && regex.test(token.text)) { | ||
var parsed = regex.exec(token.text); | ||
self.fetchXHR(parsed[1], parsed[2], self.server, token, msg); | ||
} | ||
} | ||
return tokens; | ||
} | ||
} | ||
|
||
this.rodbCSS = null; | ||
this.server = this.settings.get('addon.rodb.server'); | ||
} | ||
|
||
onEnable() { | ||
if(this.rodbCSS == null){ | ||
this.rodbCSS = document.head.appendChild(createElement('link', { | ||
href: STYLE_RO, | ||
id: 'rodb-css', | ||
rel: 'stylesheet', | ||
type: 'text/css', | ||
crossOrigin: 'anonymous' | ||
})); | ||
} | ||
|
||
this.log.info('Enabling support for divine-pride links.'); | ||
this.chat.addTokenizer(this.messageFilter); | ||
this.emit('chat:update-lines'); | ||
} | ||
|
||
onDisable() { | ||
if(this.rodbCSS != null){ | ||
document.getElementById("rodb-css").remove(); | ||
this.rodbCSS = null; | ||
} | ||
this.chat.removeTokenizer(this.messageFilter); | ||
this.emit('chat:update-lines'); | ||
} | ||
|
||
async fetchXHR(from, id, server, token, message){ | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "https://www.divine-pride.net/api/database/"+from+"/" + id + "?apiKey=92f0c44ff2bded0973a905cfc928cd66&server="+server, true); | ||
|
||
xhr.onreadystatechange = () => { | ||
if (xhr.readyState === XMLHttpRequest.DONE) { | ||
const status = xhr.status; | ||
if (status === 0 || (status >= 200 && status < 400)) { | ||
var parsed = JSON.parse(xhr.responseText); | ||
if(parsed["status"] != null) | ||
return; | ||
|
||
parsed["description"] = parsed["description"].replaceAll(/<a href.*?>/g, ''); | ||
parsed["description"] = parsed["description"].replaceAll('</a>', ''); | ||
parsed["description"] = sanitize(parsed["description"]); | ||
parsed["description"] = parsed["description"].replaceAll(/(?:\r\n|\r|\n)/g, '<br>'); | ||
parsed["description"] = parsed["description"].replaceAll('^000000', '</font>'); | ||
parsed["description"] = parsed["description"].replaceAll(/\^([0-9a-fA-F]{6})/g, "<font color=\"#$1\">"); | ||
|
||
token.type = "rodb"; | ||
token.roname = parsed["name"]; | ||
token.description = parsed["description"]; | ||
token.roid = id; | ||
token.roserver = server; | ||
|
||
this.emit("chat:update-line", message.id, false); | ||
|
||
} else { | ||
if(server == "kRO") | ||
return | ||
if(server == "iRO"){ | ||
this.fetchXHR(from, id, "kRO", token, message); | ||
return; | ||
} | ||
this.fetchXHR(from, id, "iRO", token, message); | ||
} | ||
} | ||
}; | ||
xhr.send(); | ||
} | ||
} | ||
|
||
RagnarokDatabase.register(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"enabled": true, | ||
"unlisted": true, | ||
"requires": [], | ||
"version": "1.0.1", | ||
"icon": "https://cdn.frankerfacez.com/badge/2/4/solid", | ||
"short_name": "rodb", | ||
"name": "Ragnarok Online Database", | ||
"author": "Wizzzzard", | ||
"description": "This plugin enables the pulling of data from the divine-pride.net database and displaying it in the chat when a link is provided.", | ||
"website": "https://blog.wizzzzard.moe", | ||
"settings": "add_ons.rodb", | ||
"created": "2024-03-16T11:00:00.000Z", | ||
"updated": "2024-03-17T11:00:00.000Z" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
.dp-tooltip .title, .dp-tooltip .subtitle { | ||
font-family: "Palatino Linotype", "Georgia", "Times", serif; | ||
color: #F3E6D0; | ||
font-weight: normal; | ||
margin-bottom: 6px !important; | ||
} | ||
|
||
.dp-tooltip .dp-tooltip-head h3 a{ | ||
color: #000000; | ||
font-size: 16px; | ||
height: 28px; | ||
line-height: 30px; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
text-align: left; | ||
} | ||
|
||
.dp-tooltip-item .dp-tooltip-head { | ||
height: 25px; | ||
width: 280px; | ||
padding: 0px 15px !important; | ||
background: url("https://static.divine-pride.net/images/ui/collection_header.png") no-repeat; | ||
} | ||
|
||
.dp-tooltip-item .dp-icon-item { | ||
float: left; | ||
margin-right: 10px !important; | ||
margin-bottom: 10px !important; | ||
} | ||
|
||
.dp-tooltip .dp-tooltip-body { | ||
position: relative; | ||
padding: 10px !important; | ||
max-width: 258px !important; | ||
height: 100px; | ||
background: url("https://static.divine-pride.net/images/ui/collection_line.png"); | ||
box-sizing: content-box; | ||
|
||
} | ||
|
||
.dp-tooltip-item .dp-icon-item { | ||
float: left; | ||
margin-right: 10px !important; | ||
margin-bottom: 10px !important; | ||
} | ||
|
||
.dp-icon-item { | ||
-moz-box-shadow: 0 0 5px #000; | ||
-webkit-box-shadow: 0 0 5px #000; | ||
box-shadow: 0 0 5px #000; | ||
} | ||
|
||
.dp-icon-item { | ||
border: 1px solid black; | ||
background: no-repeat left top; | ||
-moz-border-radius: 2px; | ||
-webkit-border-radius: 2px; | ||
border-radius: 2px; | ||
} | ||
|
||
.dp-icon-item .icon-item-inner { | ||
display: block; | ||
background: no-repeat center center; | ||
border: 1px solid black; | ||
font-size: 1px; | ||
line-height: normal; | ||
text-align: center; | ||
overflow: hidden; | ||
} | ||
|
||
.dp-icon-item-large .icon-item-default { | ||
width: 75px; | ||
height: 100px; | ||
} | ||
|
||
.dp-icon-item-white { | ||
border-color: #2d1c0f; | ||
border-right-color: #382213; | ||
border-bottom-color: #402715; | ||
} | ||
|
||
.dp-item-properties p { | ||
margin: 0 !important; | ||
} | ||
|
||
.dp-item-properties .indent { | ||
padding-left: 18px !important; | ||
} | ||
|
||
.dp-item-properties .value { | ||
color: #ded2ab; | ||
} | ||
|
||
.dp-item-properties .item-armor-weapon .dps { | ||
font-size: 175%; | ||
line-height: 100%; | ||
} | ||
|
||
.dp-item-properties .item-requirement { | ||
color: #A99877; | ||
} | ||
|
||
.dp-item-properties .dp-color-blue .value { | ||
color: #bda6db !important; | ||
} | ||
|
||
.dp-item-properties .dp-color-gold .value { | ||
color: white !important; | ||
} | ||
|
||
.dp-item-properties .item-type, .dp-item-properties .item-type-right { | ||
margin-top: 0 !important; | ||
} | ||
|
||
.dp-item-properties .item-type-right { | ||
float: right; | ||
text-align: right; | ||
} | ||
|
||
.dp-item-properties .item-before-effects { | ||
display: none; | ||
} | ||
|
||
.dp-tooltip .dp-tooltip-foot { | ||
height: 7px; | ||
width: 280px; | ||
padding: 0px 15px !important; | ||
background: url("https://static.divine-pride.net/images/ui/collection_foot.png") no-repeat; | ||
} | ||
|
||
.dp-tooltip ul { | ||
list-style-type: none; | ||
padding-left: 0px; | ||
margin-top: 0px; | ||
height: 105px; | ||
overflow-y: scroll; | ||
scrollbar-width: thin; | ||
} |