自动复制pushbullet最后一条文字信息

auto copy last message when pushbullet push a new message

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name            自动复制pushbullet最后一条文字信息
// @description     auto copy last message when pushbullet push a new message
// @include         https://www.pushbullet.com
// @version         0.2
// @author          yechenyin
// @namespace	    https://greasyfork.org/users/3586-yechenyin
// @match           https://www.pushbullet.com*
// @require	        https://code.jquery.com/jquery-1.11.2.min.js
// @grant           GM_setClipboard
// @run-at          document-end
// ==/UserScript==


jQuery.fn.inserted = function(action) {
  var selector = this.selector;
  var reaction = function(records) {
    records.map(function(record) {
      if (record.target !== document.body && $(record.target).find(selector).length) {
        action.call($(record.target).find(selector).last());
      }
    });
  };

  var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  if (MutationObserver) {
    var observer = new MutationObserver(reaction);
    observer.observe(document.body, {
      childList: true,
      subtree: true
    });
  } else {
    //setInterval(reaction, 100);
  }
};

console.log($('.text-part').last().text());
$('.text-part').inserted(function () {
    GM_setClipboard($('.text-part').last().text().replace(/\s+$/, ''));
});