Hack Forums
[Userscript] PM Notifications - Checks for new PMs every 60 seconds! - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88)
+---- Forum: Computing Lounge (https://hackforums.net/forumdisplay.php?fid=8)
+---- Thread: [Userscript] PM Notifications - Checks for new PMs every 60 seconds! (/showthread.php?tid=4267653)



PM Notifications - Checks for new PMs every 60 seconds! - 'Snorlax - Jun 4, 2014

Hello again

I made this userscript in a few minutes. I thought it was a good idea to be honest.

What it does is when you visit a page, it will check if you get a new PM every 60 seconds. If you get a new PM, it will ask you if you want to read the PM.
However, if you are typing, it will simply tell you that you got a new message (you can accidentally press redirect if you're typing).

IF YOU ARE TYPING
[Image: 9fs2E.png]

IF YOU ARE NOT TYPING
[Image: 9fs4v.png]
(Annuller means Cancel)

For Firefox get GreaseMonkey.
For Chrome get TamperMonkey.
For other browsers: Get Chrome.

Go add a new script and put this code into the script:

PHP Code

<?php 
// ==UserScript==
// @name      Hack Forums PM Notifications
// @namespace      Snorlax
// @description     Notifies you when you receive a new PM
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
// @grant      GM_getValue
// @grant      GM_setValue
// @grant      GM_openInTab
// @include      *hackforums.net/*
// @version      1.0
// ==/UserScript==

function run() {
    $.
get("upgrade.php", function(data) {
      if($(
data).find("strong:contains('unread private message')").length) {
      
message = $(data).find("strong:contains('unread private message')").text();
      
username = $(data).find("strong:contains('unread private message')").next().text();
      
messageURL = $(data).find("strong:contains('unread private message')").next().next().attr("href");
      
regex = /You have (.*?) unread private message/;
      match = 
regex.exec(message);
      if(match[
1] == "one") {
      match[
1] = "1";
      }
      if(match[
1] > GM_getValue("messages")) {
      if (
confirm('You got a new message from: ' + username + '\nDisplay it now?')) {
      
GM_openInTab("https://hackforums.net/" + messageURL);
      }
      }
      
message = match[1];
      } else {
      
message = 0;
      }
      
GM_setValue("messages", message);
    });
    
console.log("Amount of messages: " + GM_getValue("messages"));
}
setInterval(function() {
    
run();
}, 
60000); 

I chose upgrade.php because it requires basically no resources. That means less load on the server and faster response for you!

Report any bugs and please give me some feedback here! Thanks :)


* - ℳanny - Jun 4, 2014

I can confirm this works. Great user script snorlax <3.


* - 'Snorlax - Jun 4, 2014

(Jun 4, 2014 05:08 PM)#Herb Wrote:  I can confirm this works. Great user script snorlax ♥.

Whoa you're fast haha. Thanks a lot! I love making this stuff for you guys.


* - Roger Waters - Jun 4, 2014

I can also confirm that this works. Keep up the good work 'Snorlax!


* - _wind - Jun 4, 2014

Great script as usual. For a few minutes, you're really fast!


* - 'Snorlax - Jun 4, 2014

(Jun 4, 2014 05:10 PM)Un.titled Wrote:  Great script as usual. For a few minutes, you're really fast!

Haha yep! I think the whole thing through in my head, and then I basically just do it. TALENTS 🤣

Thanks, Roger :3


* - Pillows - Jun 4, 2014

Do you think you can make this so that it displays a chrome notification instead? (Like the one you get when you receive an email in chrome?) That way it's less intrusive.


* - 'Snorlax - Jun 4, 2014

(Jun 4, 2014 05:11 PM)Pillows Wrote:  Do you think you can make this so that it displays a chrome notification instead? (Like the one you get when you receive an email in chrome?) That way it's less intrusive.

Dude I tried so hard to make it work. Literally spent like 2 hours trying to find various scripts and make it work. That was my first intention, but I haven't been able to find a way.
Since it's an userscript, the user have to press a button (YES.. PRESS) to make it ask for permissions to create desktop notifications. And even with that it didn't work...


* - 'Snorlax - Jun 4, 2014

(Jun 4, 2014 05:16 PM)xadamxk Wrote:  So many userscripts in one day, oh muy gosh D:

I KNOW RIGHT. It's the best day of my life :')
Nah jk. My head is sore from coding like 6 hours straight.


* - Oak. - Jun 4, 2014

This looks great and also works great!


* - 'Snorlax - Jun 6, 2014

PLEASE THANK 1n9i9c7om! He told me about GM_openInTab which allows me to open a message in a new tab. JUST what I needed!

Update your userscript with my newly updated one and it will open in a new tab instead!


* - 1n9i9c7om - Jun 6, 2014

(Jun 6, 2014 01:34 PM)Snorlax Wrote:  PLEASE THANK 1n9i9c7om! He told me about GM_openInTab which allows me to open a message in a new tab. JUST what I needed!

Update your userscript with my newly updated one and it will open in a new tab instead!

Huh.... no problem, luckily we randomly came up with the topic userscripts xD