// ==UserScript==
// @title nishino_ameblo_br
// @name nishino_ameblo_br
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://ameblo.jp/nishino-akihiro/entry*
// @match https://gamp.ameblo.jp/nishino-akihiro/entry*
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
// ==/UserScript==
while (document.getElementById("test1") == null) {
var result = document.evaluate('//div[@class="skin-entryBody" or @class="entry-text"]//*[self::div or self::p][not(.//text() or .//img or .//iframe)]', document, null, 7, null);
for (var i = 0; i < result.snapshotLength; i++) {
result.snapshotItem(i).classList.add("div_br");
}
var result3 = document.evaluate('descendant::div[@class="div_br"][last()]', document, null, 7, null);
result3.snapshotItem(0).id = "test1";
}
//消しきれない空div削除
var result2 = document.evaluate('//div[@class="div_br"][not(.//br)]', document, null, 7, null);
for (var z = 0; z < result2.snapshotLength; z++) {
result2.snapshotItem(z).remove();
}
//生br処理
/*var listArray = document.querySelectorAll('div+br');
for (var a = 0; a < listArray.length; a++) {
listArray[a].classList.add("div_and_n_br");
}*/
//lastdiv処理
var result4 = document.evaluate('//div[@class="skin-entryBody" or @class="entry-text"]/descendant::div[not(@class)][last()][./following-sibling::div[@class="div_br"] and ./preceding-sibling::div[@class="div_br"]]|descendant::div[@class="div_br"][last()]/preceding-sibling::div[not(@class)][1]', document, null, 7, null);
for (var k = 0; k < result4.snapshotLength; k++) {
result4.snapshotItem(k).classList.add("div_last");
}
//div[./lastbr]にクラス付加
var result5 = document.evaluate('//div[@class="skin-entryBody" or @class="entry-text"]//div[not(@class) or @id][./*[contains(@class,"div_br") or contains(@class,"div_and_n_br")][last()][not(./following-sibling::node()[string-length(normalize-space())>1])]]', document, null, 7, null);
for (var x = 0; x < result5.snapshotLength; x++) {
result5.snapshotItem(x).classList.add("child_br_last");
}
//child_br_lastクラスの祖先ノードにクラス付加
var result6 = document.evaluate('//div[contains(@class,"child_br_last")]/ancestor::div[not(@class)]', document, null, 7, null);
for (var y = 0; y < result6.snapshotLength; y++) {
result6.snapshotItem(y).classList.add("div_child_br_last");
}
//エントリ外のdiv_child_br_lastクラス削除
var result7 = document.evaluate('//div[@class="div_child_br_last"][.//div[@class="skin-entryBody" or @class="entry-text"]]', document, null, 7, null);
for (var c = 0; c < result7.snapshotLength; c++) {
result7.snapshotItem(c).classList.remove("div_child_br_last");
}
//div_child_br_lastのツリー構造を破壊
$(function () {
$("div.div_child_br_last").replaceWith(function () {
return $(this).contents();
});
});
/*$(function(){
$("div.child_br_last").replaceWith(function() {
return $(this).contents();
});
});*/
//生テキスト処理
var result8 = document.evaluate('//div[@class="skin-entryBody" or @class="entry-text"]//div[./text()[string-length(normalize-space())>1][./following-sibling::* or ./preceding-sibling::*]]', document, null, 7, null);
for (var j = 0; j < result8.snapshotLength; j++) {
//result8.snapshotItem(j).insertAdjacentHTML("afterbegin","<div></div>");
result8.snapshotItem(j).insertAdjacentHTML("beforeend", "<div></div>");
}
var result9 = document.evaluate('//div[@class="skin-entryBody" or @class="entry-text"]//div[@class="div_br" or @class="child_br_last"][./following-sibling::text()[string-length(normalize-space())>1][./following-sibling::div[@class="div_br"] or self::br]][last()]', document, null, 7, null);
result9.snapshotItem(0).insertAdjacentHTML("afterend", "<div></div>");