Skip to content

Commit

Permalink
Fix donation popup
Browse files Browse the repository at this point in the history
  • Loading branch information
a161803398 committed May 10, 2020
1 parent 82d3624 commit e56e22b
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 91 deletions.
5 changes: 5 additions & 0 deletions src/www/assets/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,9 @@ input[type=range]::-webkit-slider-thumb {

.warning {
color: #f00;
}

.not-working {
color: #808080;
text-decoration: line-through;
}
13 changes: 6 additions & 7 deletions src/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<h1 id="indicator" style="display:none;"><img id="loadingImg" src="assets/loading.gif" alt="Loading"><br>
<span id="captureHint">Please Wait...</span>
</h1>
<div id="infoText" class="hideOnCapture">Plexstorm Capture V1.0.0-alpha.1<br>by a161803398</div>
<div class="warning">Donation popup is not working in this version.</div>
<div id="infoText" class="hideOnCapture">Plexstorm Capture V1.0.1-alpha.2<br>by a161803398</div>

<button id="loadChatBtn" class="hideOnCapture">Start Capturing</button><br class="hideOnCapture">

Expand All @@ -34,7 +33,7 @@ <h1 id="indicator" style="display:none;"><img id="loadingImg" src="assets/loadin
<input id="playTimeSelect" type="number" min="0" value="500" style="width: 50px;"><span id="playTimeHint2">ms video playing time</span>
<br>
<button id="musicDonateTestBtn">Test YouTube Video</button>
<button id="phFastDonateTestBtn">Test Pornhub Video</button><br>
<button id="phFastDonateTestBtn" disabled>Test Pornhub Video</button><br>

<button id="stopBtn">Terminate donate popup</button>
<button id="showHideBtn">Show/Hide donate Video</button><br>
Expand All @@ -58,8 +57,8 @@ <h1 id="indicator" style="display:none;"><img id="loadingImg" src="assets/loadin
<input type="checkbox" id="playYTChk" checked>
<label for="playYTChk" id="playYTChkHint">Play YouTube Video</label><br>

<input type="checkbox" id="playPHChk" checked>
<label for="playPHChk" id="playPHChkHint">Play Pornhub Video</label><br>
<input type="checkbox" id="playPHChk" disabled>
<label for="playPHChk" id="playPHChkHint" class="not-working">Play Pornhub Video</label><br>

<input type="checkbox" id="defaultShowVideoChk" checked>
<label for="defaultShowVideoChk" id="defaultShowVideoChkHint">Show Video by default</label><br>
Expand All @@ -74,8 +73,8 @@ <h1 id="indicator" style="display:none;"><img id="loadingImg" src="assets/loadin
<span id="recordsHint">Chat records save in chat_logs folder</span><br>
<span id="chatUrlHint">Chat Room:</span>http://localhost:1069<br>
<span id="donateUrlHint">Donation:</span>http://localhost:1069/donate<br>
<span id="subscriptUrlHint">Subscription:</span>http://localhost:1069/subscript<br>
<span id="topDonateUrlHint">Top Donate:</span>http://localhost:1069/topDonate<br>
<span class="not-working"><span id="subscriptUrlHint">Subscription:</span>http://localhost:1069/subscript</span><br>
<span class="not-working"><span id="topDonateUrlHint">Top Donate:</span>http://localhost:1069/topDonate</span><br>
<a id="donateLink" href="#">Support development: www.patreon.com/a1618</a>
</div>
<input type="checkbox" id="alwaysOnTopChk">
Expand Down
129 changes: 61 additions & 68 deletions src/www/js/decodeMsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@ function createElementFromHTML(htmlString) {
}

function getPDCount(str){
let pd = 0;
for(let i = 0; i < str.length; i++){
const curCharCode = str.charCodeAt(i);
if(curCharCode >= 48 && curCharCode <= 57){ //0 to 9
pd *= 10;
pd += curCharCode - 48;
}
}
return pd;
return parseInt(str.match(/has tipped (\d+)/)[1]);
}

const userMap = new Map();
Expand Down Expand Up @@ -75,75 +67,76 @@ function decodeMsg(tar){
msgText: ''
};


const userSpan = decodeElement.children[0];
if (userSpan) {
msgObj.userName = userSpan.innerText.trim();
if(msgObj.userName == "asixteen"){
msgObj.userName = "a161803398";
if (decodeElement.classList.contains('highlight-message')) {
msgObj.msgType = 3;

const msgP = decodeElement.children[0];

const userSpan = msgP.children[0];
if (userSpan) {
msgObj.userName = userSpan.innerText.trim();
}

if (msgP) {
msgObj.msgText = msgP.innerText.trim();
}
} else {
const userSpanWrapper = decodeElement.children[0];
const userSpan = userSpanWrapper.children[0]

if (userSpan) {
msgObj.userName = userSpan.innerText.trim();
}else{
msgObj.userName = userSpanWrapper.innerText.trim();
}

const msgP = decodeElement.children[1];

if (msgP) {
msgObj.msgText = msgP.innerText.trim();
}
}

// FIXME: don't work anymore
// const classList = userSpan.classList;
// if(classList.contains('color-female')){
// msgObj.userSex = 1;
// }else if(classList.contains('color-trans')){
// msgObj.userSex = 2;
// }
let userObj = null;
if(userMap.has(msgObj.userName)){ //old user
userObj = userMap.get(msgObj.userName); //retrieve userObj
}else{
userObj = {preMsg: null, ucid: userMap.size};
userMap.set(msgObj.userName, userObj); //put userObj to map and increase map size
}
msgObj.ucid = userObj.ucid; //set ucid

const msgP = decodeElement.children[1];

if (msgP) {
msgObj.msgText = msgP.innerText.trim();

let userObj = null;
if(userMap.has(msgObj.userName)){ //old user
userObj = userMap.get(msgObj.userName); //retrieve userObj
}else{
userObj = {preMsg: null, ucid: userMap.size};
userMap.set(msgObj.userName, userObj); //put userObj to map and increase map size
if(msgObj.msgType == 3 || msgObj.msgType == 4){
if(msgObj.msgType == 3){
msgObj['pdAmount'] = getPDCount(msgObj.msgText);
}else {
msgObj.msgText = curLang.msg['subscript'];
}
msgObj.ucid = userObj.ucid; //set ucid

if(msgObj.msgType == 3 || msgObj.msgType == 4){
if(msgObj.msgType == 3){
msgObj['pdAmount'] = getPDCount(msgObj.msgText);
msgObj.msgText = curLang.msg['donate'] + msgObj['pdAmount'] + 'PD';
}else {
msgObj.msgText = curLang.msg['subscript'];
}
msgObj['rndNum'] = Math.floor(999999999 * Math.random());

if(userObj.preMsg != null){
msgObj['preMsg'] = userObj.preMsg;

msgObj['rndNum'] = Math.floor(999999999 * Math.random());

//if(typeof preUserMsgMap[msgObj.userName] != "undefined"){

if(userObj.preMsg != null){
//msgObj['preMsg'] = preUserMsgMap[msgObj.userName];
msgObj['preMsg'] = userObj.preMsg;

if(msgObj.msgType == 3){ //for donate only
const preMsgObj = decodeDonateMsg(msgObj['preMsg']);
msgObj['preMsg'] = preMsgObj.userMsg;
if(preMsgObj.vid != null){
msgObj['vid'] = preMsgObj.vid;
msgObj['startTime'] = preMsgObj.startTime;
msgObj['playTime'] = setting.playTimeUnit * msgObj['pdAmount'];
msgObj['videoType'] = preMsgObj.videoType;
}
}

if(!setting.readMsg){
msgObj['preMsg'] = "";
if(msgObj.msgType == 3){ //for donate only
const preMsgObj = decodeDonateMsg(msgObj['preMsg']);
msgObj['preMsg'] = preMsgObj.userMsg;
if(preMsgObj.vid != null){
msgObj['vid'] = preMsgObj.vid;
msgObj['startTime'] = preMsgObj.startTime;
msgObj['playTime'] = setting.playTimeUnit * msgObj['pdAmount'];
msgObj['videoType'] = preMsgObj.videoType;
}
}else{
msgObj['preMsg'] = "";
}


if(!setting.readMsg){
msgObj['preMsg'] = "";
}
}else{
//preUserMsgMap[msgObj.userName] = msgObj.msgText; //record pre-message
userObj.preMsg = msgObj.msgText; //record pre-message
msgObj['preMsg'] = "";
}
}
}else{
userObj.preMsg = msgObj.msgText; //record pre-message
}
return msgObj;
}
58 changes: 42 additions & 16 deletions src/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ donateLink.addEventListener("click", ()=>{
function updateSetting(){
setting.readMsg = readMsgChk.checked;
setting.playYT = playYTChk.checked;
setting.playPH = playPHChk.checked;
setting.playPH = false; // FIXME
setting.defaultShowVideo = defaultShowVideoChk.checked;
setting.logToFile = logToFileChk.checked;

Expand Down Expand Up @@ -86,7 +86,7 @@ function updateState(){
loadSetting();
readMsgChk.checked = setting.readMsg;
playYTChk.checked = setting.playYT;
playPHChk.checked = setting.playPH;
playPHChk.checked = false; // FIXME
defaultShowVideoChk.checked = setting.defaultShowVideo;
logToFileChk.checked = setting.logToFile;

Expand Down Expand Up @@ -267,24 +267,50 @@ function printMsg(jsonMsg){
}
}

musicDonateTestBtn.addEventListener('click', (e)=>{
printMsg(decodeMsg('<div class="row message flex items-center type-normal type-normal"><div class="user flex items-center"><i aria-hidden="true" class="far mr-1 fa-venus"></i> <span class="username color-male">a161803398</span><span class="placeholder mx1">·</span></div> <span class="timestamp grey mr1"><time datetime="Thu May 03 2018 12:51:11 GMT+0800 (台北標準時間)" title="5/3/2018, 12:51:11 PM">2 minutes ago</time></span><p class="my-4 message-text white">' + curLang.msg['testYouTubeDonateMsg'] + '</p></div>'));
printMsg(decodeMsg('<div class="row message flex items-center type-normal type-tip"><div class="flex justify-center mx-auto"><div class="user flex items-center mr1"><i aria-hidden="true" class="far mr-2 fa-mars"></i> <span class="username color-male">a161803398</span></div><p class="my-4 message-text">has tipped<span class="white ml1">17 PD</span></p></div></div>'));
if(curTopDonateMsg == ""){
//put some dummy message
updateTopDonate('a161803398: <span class="hightlight">Test Donate</span>');
musicDonateTestBtn.addEventListener('click', (e)=>{
const msgObj = {
type: 'chat',
msgType: 3, //type-tip
userName: 'a161803398',
userSex: 0,//male
msgText: curLang.msg['donate'] + '17PD',
pdAmount: 17,
rndNum: parseInt(donateSelect.value),
ucid: 0
};

const preMsgObj = decodeDonateMsg(setting.readMsg ? curLang.msg['testYouTubeDonateMsg'] : "");
msgObj['preMsg'] = preMsgObj.userMsg;
if(preMsgObj.vid != null){
msgObj['vid'] = preMsgObj.vid;
msgObj['startTime'] = preMsgObj.startTime;
msgObj['playTime'] = setting.playTimeUnit * msgObj['pdAmount'];
msgObj['videoType'] = preMsgObj.videoType;
}

printMsg(msgObj);
});

phFastDonateTestBtn.addEventListener('click', (e)=>{
printMsg(decodeMsg('<div class="row message flex items-center type-normal type-normal"><div class="user flex items-center"><i aria-hidden="true" class="far mr-1 fa-venus"></i> <span class="username color-male">a161803398</span><span class="placeholder mx1">·</span></div> <span class="timestamp grey mr1"><time datetime="Thu May 03 2018 12:51:11 GMT+0800 (台北標準時間)" title="5/3/2018, 12:51:11 PM">2 minutes ago</time></span><p class="my-4 message-text white">' + curLang.msg['testPornHubDonateMsg'] + '</p></div>'));
printMsg(decodeMsg('<div class="row message flex items-center type-normal type-tip"><div class="flex justify-center mx-auto"><div class="user flex items-center mr1"><i aria-hidden="true" class="far mr-2 fa-mars"></i> <span class="username color-male">a161803398</span></div><p class="my-4 message-text">has tipped<span class="white ml1">10 PD</span></p></div></div>'));
if(curTopDonateMsg == ""){
//put some dummy message
updateTopDonate('a161803398: <span class="hightlight">Test Donate</span>');
phFastDonateTestBtn.addEventListener('click', (e)=>{
const msgObj = {
type: 'chat',
msgType: 3, //type-tip
userName: 'a161803398',
userSex: 0,//male
msgText: curLang.msg['donate'] + '17PD',
pdAmount: 17,
rndNum: parseInt(donateSelect.value),
ucid: 0
};

const preMsgObj = decodeDonateMsg(setting.readMsg ? curLang.msg['testPornHubDonateMsg'] : "");
msgObj['preMsg'] = preMsgObj.userMsg;
if(preMsgObj.vid != null){
msgObj['vid'] = preMsgObj.vid;
msgObj['startTime'] = preMsgObj.startTime;
msgObj['playTime'] = setting.playTimeUnit * msgObj['pdAmount'];
msgObj['videoType'] = preMsgObj.videoType;
}

printMsg(msgObj);
});


Expand Down

0 comments on commit e56e22b

Please sign in to comment.