Skip to content

Instantly share code, notes, and snippets.

@gh640
Created February 7, 2016 01:04
Show Gist options
  • Select an option

  • Save gh640/e300647bf2c73e4cd64c to your computer and use it in GitHub Desktop.

Select an option

Save gh640/e300647bf2c73e4cd64c to your computer and use it in GitHub Desktop.
Drupal 7 でワンクリックで投稿画面を開くブックマークレット
/**
* Drupal 7 でワンクリックで投稿画面を開くブックマークレット
*
* Prepopulate モジュールが有効になっている必要があります
*/
javascript: (function(){
'use strict';
var BASE_URL,
NODE_TYPE,
current_title_url;
/* Set drupal base url and node type */
BASE_URL = 'Drupal サイトの URL を入力します';
NODE_TYPE = '対象のノードタイプのマシン名を入力します';
current_title_url = get_current_title_url();
open_node_add_page(BASE_URL, NODE_TYPE, current_title_url[0], current_title_url[1]);
/* Get current page title and url */
function get_current_title_url() {
var title_tags = document.getElementsByTagName('title'),
title = title_tags ? title_tags[0].innerText : '',
url = window.location.href;
return [title, url];
}
/* Open node page with title and body set */
function open_node_add_page(base_url, node_type, title, body) {
var url_node_post = base_url + '/node/add/' + node_type,
parameters;
parameters = '?';
parameters += 'edit[title]=' + encodeURIComponent(title);
parameters += '&';
parameters += 'edit[body][und][0][value]=' + encodeURIComponent(body);
window.open(url_node_post + parameters);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment