Permalink
Please sign in to comment.
Browse files
Switched to Google Script
Switched from client side jQuery based addon to server side Google Apps script
| @@ -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); | ||
| + }); | ||
| +} |
| @@ -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