-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AmirCpu
authored and
AmirCpu
committed
Dec 8, 2021
1 parent
c2e1e6d
commit aa4652f
Showing
12 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,142 @@ | ||
var targetWindow = null; | ||
|
||
function NorificationManager(prefix) { | ||
var nurl = {}, nbtns = {}, ncounter = 0; | ||
function id() { | ||
return prefix + (ncounter++); | ||
} | ||
function create(title, message, options) { | ||
var nid = id(); | ||
var opts = { | ||
type: "basic", | ||
title: title, | ||
message: message, | ||
iconUrl: "icon128.png" | ||
}; | ||
nurl[nid] = options.url; | ||
nbtns[nid] = options.buttons; | ||
if (options.buttons) { | ||
opts.buttons = []; | ||
for (var i = 0; i < options.buttons.length; i++) { | ||
opts.buttons[i] = { title: options.buttons[i].title }; | ||
options.buttons[i].iconUrl && (opts.buttons[i].iconUrl = options.buttons[i].iconUrl); | ||
} | ||
} | ||
chrome.notifications.create( | ||
nid, | ||
opts, | ||
function (notificationId) { } | ||
); | ||
return nid; | ||
} | ||
function remove(notificationId) { | ||
chrome.notifications.clear(notificationId, function () { }); | ||
delete nurl[notificationId]; | ||
delete nbtns[notificationId]; | ||
} | ||
chrome.notifications.onClicked.addListener(function (notificationId) { | ||
if (nurl.hasOwnProperty(notificationId)) { | ||
nurl[notificationId] && window.open(nurl[notificationId]); | ||
remove(notificationId); | ||
} | ||
}); | ||
chrome.notifications.onButtonClicked.addListener(function (notificationId, index) { | ||
if (nbtns.hasOwnProperty(notificationId)) { | ||
var b = nbtns[notificationId][index]; | ||
b.url && window.open(b.url); | ||
(typeof (b.onclick) == 'function') && b.onclick(notificationId, index); | ||
remove(notificationId); | ||
} | ||
}); | ||
return { | ||
create: create, | ||
remove: remove | ||
} | ||
} | ||
|
||
var i = 0; | ||
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { | ||
try{ | ||
console.log(request.message); | ||
|
||
//check for fcuse tab | ||
chrome.windows.getCurrent(function (win) { | ||
targetWindow = win; | ||
}); | ||
|
||
// alert(targetWindow.state=='minimized'); | ||
|
||
// alert(targetWindow.focused); | ||
|
||
// alert(request.whiteBoardIsFullScreen); | ||
|
||
//میخوای بگیم م.اقعی که کاربر صفحه رو میبینه و داخل وایتبرد نیست پیام ارسال نکن | ||
if ( targetWindow.focused == true && request.whiteBoardIsFullScreen == false) | ||
{ | ||
chrome.notifications.getAll((items) => { | ||
if ( items ) { | ||
for (let key in items) { | ||
chrome.notifications.clear(key); | ||
} | ||
} | ||
}); | ||
return 0; | ||
} | ||
|
||
var _notificationManager = new NorificationManager(`sample-prefix-${i++}`); //prefix must be unique | ||
|
||
//---------------------- | ||
var options = { | ||
url: "", //(optional) Click-to-open URL | ||
buttons: [ //(optional) button | ||
{ title: "بستن همه", onclick: function (notificationId, index) { | ||
|
||
chrome.notifications.getAll((items) => { | ||
if ( items ) { | ||
for (let key in items) { | ||
chrome.notifications.clear(key); | ||
} | ||
} | ||
}); | ||
|
||
} }, | ||
{ title: "رفتن به چت", url: `${request.url}` } //button item: onclick or url | ||
] | ||
}; | ||
var _notificationManager = nman.create(request.name, request.message, options); | ||
} | ||
catch(e){ | ||
console.log(e); | ||
} | ||
|
||
}) | ||
|
||
// Set up a click handler so that we can merge all the windows. | ||
chrome.browserAction.onClicked.addListener(function (re, res, resf) { | ||
|
||
var nman = new NorificationManager(`sample-prefix-${i++}`); //prefix must be unique | ||
|
||
//---------------------- | ||
var options = { | ||
url: "", //(optional) Click-to-open URL | ||
buttons: [ //(optional) button | ||
{ title: "بستن همه", onclick: function (notificationId, index) { | ||
|
||
chrome.notifications.getAll((items) => { | ||
if ( items ) { | ||
for (let key in items) { | ||
chrome.notifications.clear(key); | ||
} | ||
} | ||
}); | ||
|
||
} }, | ||
{ title: "بعدا پاسخ میدم", onclick: function (notificationId, index) { | ||
document.querySelector('#message-input').parentElement.querySelector('button').click() | ||
} } | ||
] | ||
}; | ||
var nid = nman.create("AmirCpu", "Description Message", options); | ||
}); | ||
|
||
// chrome.windows. |
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,112 @@ | ||
//#region init value | ||
var messageHashList = []; | ||
var curentUserName = ''; | ||
|
||
arabicNumbers = ["١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩", "٠"]; | ||
persianNumbers = ["۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹", "۰"]; | ||
englishNumbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]; | ||
//#endregion | ||
|
||
//#region public methods | ||
String.prototype.hashCode = function () { | ||
var hash = 0, i, chr; | ||
if (this.length === 0) return hash; | ||
for (i = 0; i < this.length; i++) { | ||
chr = this.charCodeAt(i); | ||
hash = ((hash << 5) - hash) + chr; | ||
hash |= 0; // Convert to 32bit integer | ||
} | ||
return hash; | ||
}; | ||
|
||
String.prototype.toEnglish = function () { | ||
var english = '', i, chr; | ||
if (this.length === 0) | ||
return english; | ||
english = this; | ||
for (i = 0; i < 10; i++) { | ||
english = english.replace(arabicNumbers[9 - i], englishNumbers[i]); | ||
english = english.replace(persianNumbers[i], englishNumbers[i]); | ||
} | ||
return english; | ||
}; | ||
//#endregion | ||
|
||
//#region tag selected | ||
var select_chatArea = '#chat-messages'; | ||
var select_currentUserName = '[class^="userNameMain"]>span'; | ||
var select_chatMessage = '#chat-messages [class^="message"]'; | ||
var select_whiteBoardIsFullScreen = '.icon--2q1XXw.icon-bbb-exit_fullscreen'; | ||
var select_dashBoardBTN = 'body header button'; | ||
var select_chatMessageBTN = '#chat-toggle-button'; | ||
//#endregion | ||
|
||
//check url Access: | ||
if (`${document.location.href}`.match("http.*class.*.daan.ir") != null) { | ||
|
||
//chrome.browserAction.setIcon({path: 'icon48_active.png'}); | ||
|
||
//Change icon to acctive | ||
|
||
try { | ||
var checkMessageBox = setInterval(function () { | ||
|
||
if (document.querySelector(select_chatArea) != null) { | ||
|
||
clearInterval(checkMessageBox); | ||
|
||
curentUserName = `${document.querySelector(select_currentUserName).textContent}`.trim(); | ||
|
||
document.querySelector(select_chatArea).addEventListener('DOMSubtreeModified', function (a) { | ||
|
||
var messages = document.querySelectorAll(select_chatMessage); | ||
|
||
var messageTime = new Date(new Date().toDateString() + ' ' + messages[messages.length - 1].parentElement.parentElement.querySelector('time').textContent.toEnglish()); | ||
|
||
console.log(`${messages[messages.length - 1].parentElement.parentElement.querySelector('span').textContent}`.trim().hashCode()); | ||
console.log(curentUserName.hashCode()); | ||
console.log(`${messages[messages.length - 1].parentElement.parentElement.querySelector('span').textContent}`.trim().hashCode() == curentUserName.hashCode()); | ||
console.log(messageTime.getMinutes() != new Date().getMinutes()); | ||
|
||
//check message | ||
if (messageTime.getMinutes() != new Date().getMinutes() || messageTime.getHours() != new Date().getHours() | ||
|| messageHashList.indexOf(messages[messages.length - 1].parentElement.parentElement.textContent.hashCode()) != -1 | ||
|| `${messages[messages.length - 1].parentElement.parentElement.querySelector('span').textContent}`.trim().hashCode() == curentUserName.hashCode()) { | ||
console.log("dn"); | ||
return 0; | ||
} | ||
|
||
//insert hash message | ||
messageHashList.push(messages[messages.length - 1].parentElement.parentElement.textContent.hashCode()); | ||
|
||
var lastmessage = { body: messages[messages.length - 1].textContent, name: messages[messages.length - 1].parentElement.parentElement.querySelector('div').querySelector('div').textContent }; | ||
|
||
chrome.runtime.sendMessage({ | ||
url: window.location.href, | ||
name: `${lastmessage.name}`, | ||
message: `${lastmessage.body}`, | ||
whiteBoardIsFullScreen: document.body.querySelector(select_whiteBoardIsFullScreen) != null | ||
}); | ||
|
||
}, false); | ||
|
||
//more btn click to show other message | ||
document.querySelector(select_chatArea).parentElement.parentElement.addEventListener('DOMSubtreeModified', function (a) { | ||
if (document.querySelector(select_chatArea).parentElement.querySelector('button') != null) | ||
document.querySelector(select_chatArea).parentElement.querySelector('button').click(); | ||
}) | ||
} | ||
else { | ||
if (document.querySelector(select_dashBoardBTN) != null) { | ||
document.querySelector(select_dashBoardBTN).click(); | ||
document.querySelector(select_chatMessageBTN).click(); | ||
} | ||
} | ||
|
||
}, 5000); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,23 @@ | ||
|
||
{ | ||
"name": "Daan Notifications", | ||
"version": "1.0", | ||
"manifest_version": 2, | ||
"content_scripts": [ | ||
{ | ||
"matches": ["https://*.daan.ir/*"], | ||
"js": ["content.js"] | ||
} | ||
], | ||
"browser_action": { | ||
"default_title": "Daan Notifications" | ||
}, | ||
"icons": { | ||
"48": "icon48_active.png", | ||
"128": "icon128.png" | ||
}, | ||
"background": { | ||
"scripts": ["background.js"] | ||
}, | ||
"permissions": ["tabs","notifications","activeTab","https://*.daan.ir/*"] | ||
} |
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,9 @@ | ||
<html> | ||
<body> | ||
<p>Some Nice Text While Playing Song.. </p> | ||
<audio autoplay> | ||
<source src="http://www.html5rocks.com/en/tutorials/audio/quick/test.mp3" type="audio/mpeg" /> | ||
<source src="http://www.html5rocks.com/en/tutorials/audio/quick/test.ogg" type="audio/ogg" /> | ||
</audio> | ||
</body> | ||
</html> |
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,12 @@ | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<!-- <button>Count Bears</button> --> | ||
<script src="popup.js" charset="utf-8"></script> | ||
</body> | ||
</html> |
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,23 @@ | ||
document.addEventListener('DOMContentLoaded', function () { | ||
|
||
const bg = chrome.extension.getBackgroundPage() | ||
Object.keys(bg.bears).forEach(function (url) { | ||
const div = document.createElement('div') | ||
div.textContent = `${url}: ${bg.bears[url]}` | ||
document.body.appendChild(div) | ||
}) | ||
|
||
// document.querySelector('button').addEventListener('click', onclick, false) | ||
// | ||
// function onclick () { | ||
// chrome.tabs.query({currentWindow: true, active: true}, function (tabs) { | ||
// chrome.tabs.sendMessage(tabs[0].id, 'hi', setCount) | ||
// }) | ||
// } | ||
// | ||
// function setCount (res) { | ||
// const div = document.createElement('div') | ||
// div.textContent = `${res.count} bears` | ||
// document.body.appendChild(div) | ||
// } | ||
}, false) |