Permalink
Browse files

Switched to Google Script

Switched from client side jQuery based addon to server side Google Apps script
1 parent 2b79fcb commit df79037e775bff04c3ae2417e40751cf1c5410c1 @labnol committed on GitHub Apr 23, 2017
Showing with 22 additions and 52 deletions.
  1. +22 −0 gmail.js
  2. +0 −52 main.js
View
@@ -0,0 +1,22 @@
+function main() {
+
+ var label = GmailApp.getUserLabelByName("Unsubscribe");
+ var threads = label.getThreads();
+
+ threads.forEach(function(thread) {
+
+ var message = thread.getMessages()[0];
+ var value = message.getRawContent()
+ .match(/^List-Unsubscribe: ((.|\r\n\s)+)\r\n/m)[1];
+
+ if (value) {
+ var url = value.match(/<(https?:\/\/[^>]+)>/)[1];
+ if (url) {
+ var status = UrlFetchApp.fetch(url).getResponseCode();
+ Logger.log("Unsubscribe " + status + " " + url);
+ }
+ }
+
+ thread.removeLabel(label);
+ });
+}
View
52 main.js
@@ -1,52 +0,0 @@
-$().ready(function(){
-
- var last_subject = false;
-
-
- $('div.Cq div:first div:first').append('<a href="#" target="_blank" style="background:red;color:#fff;padding:5px;text-decoration:none;display:none;" id="btn_junk">Unsubscribe</a>');
-
-
-
- setInterval(function(){
-
-
- if( $('h1.ha').size() ){
-
- subject = $('h1.ha').html();
-
- if( last_subject != subject ){
-
- last_subject = subject;
-
- links = $('table.Bs').find('a');
- total = links.size();
- if( total ){
- found = false;
- i=0;
- while(i<total && !found){
-
- text = $(links[i]).html();
- url = $(links[i]).attr('href');
-
- var found = ( text.match(/unsubscribe/gi) || url.match(/unsubscribe/gi) || url.match(/nuMuMail/gi) );
- if( found ){
- $('#btn_junk').attr('href',url).show();
- }else{
- $('#btn_junk').hide();
- }
-
- i++;
- }
- }else{
- $('#btn_junk').hide();
- }
-
- }
- }
-
-
- },1000);
-
-
-
-});

0 comments on commit df79037

Please sign in to comment.