Skip to content

Instantly share code, notes, and snippets.

@JichunMa
Last active May 28, 2019 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JichunMa/6f503c933325391727262750bc9e1069 to your computer and use it in GitHub Desktop.
Save JichunMa/6f503c933325391727262750bc9e1069 to your computer and use it in GitHub Desktop.
Phabricator copy
// ==UserScript==
// @name Phabricator copy
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://code.yangqianguan.com/D*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var button = document.createElement("input");
button.setAttribute("type", "button");
var title_element = document.querySelector("#phabricator-standard-page-body > div.phui-two-column-view.phui-side-column-right.with-subheader > div > div.phui-two-column-header > div > h1 > div > div.phui-header-col2 > span")
var title = document.URL+' '+title_element.innerText.trim();
button.setAttribute("value", "Copy");
button.setAttribute('style', 'padding:3px 9px;border-radius:3px;background:rgba(71,87,120,0.1);margin-right:8px;-webkit-font-smoothing:auto;border-color:transparent;font-weight:normal;font-size:14px;margin-top:8px;color:#464C5C');
button.addEventListener("click", function(){
var input = document.createElement('input');
input.setAttribute('value', title);
document.body.appendChild(input);
input.select();
var result = document.execCommand('copy');
document.body.removeChild(input)
});
var head_element = document.querySelector("#phabricator-standard-page-body > div.phui-two-column-view.phui-side-column-right.with-subheader > div > div.phui-two-column-header > div > h1 > div > div.phui-header-col2 > div.phui-header-subheader");
head_element.appendChild(button);
}
)();
@hanfeng120
Copy link

// ==UserScript==
// @name         Test Copy
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://code.yangqianguan.com/D*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var button = document.createElement("input");
    button.setAttribute("type", "button");
    var title_element = document.querySelector("#phabricator-standard-page-body > div.phui-two-column-view.phui-side-column-right.with-subheader > div > div.phui-two-column-header > div > h1 > div > div.phui-header-col2 > span")
    var title = document.URL+' '+title_element.innerText.trim();
    button.setAttribute("value", "Copy");
    button.setAttribute('style', 'padding:3px 9px;border-radius:3px;background:rgba(71,87,120,0.1);margin-right:8px;-webkit-font-smoothing:auto;border-color:transparent;font-weight:normal;font-size:14px;margin-top:8px;color:#464C5C');

    button.addEventListener("click", function(){
   var textarea = document.createElement('textarea');
  textarea.textContent = title;
  document.body.appendChild(textarea);

  var selection = document.getSelection();
  var range = document.createRange();
//  range.selectNodeContents(textarea);
  range.selectNode(textarea);
  selection.removeAllRanges();
  selection.addRange(range);

  console.log('copy success', document.execCommand('copy'));
  selection.removeAllRanges();

  document.body.removeChild(textarea);
});
    var head_element = document.querySelector("#phabricator-standard-page-body > div.phui-two-column-view.phui-side-column-right.with-subheader > div > div.phui-two-column-header > div > h1 > div > div.phui-header-col2 > div.phui-header-subheader");

    head_element.appendChild(button);

}


)();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment