Skip to content

Commit

Permalink
新增马蜂窝旅行商城脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
woolition committed Aug 6, 2018
1 parent 1cb9d87 commit f76f78a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
64 changes: 64 additions & 0 deletions mafengwo/mfwTripMall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// ==UserScript==
// @name 马蜂窝旅游商城--获取销量价格
// @namespace https://greasyfork.org/zh-CN/users/104201
// @version 0.2
// @description 马蜂窝,旅游商城板块,把产品列表转化为表格。适用于Tampermonkey
// @author 黄盐
// @include *//www.mafengwo.cn/*
// @require https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
// @noframes
// @run-at document-end
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant window.close
// ==/UserScript==
/* jshint esversion: 6 */
;
(function() {

function makeTable() {

var items = $('a.item.clearfix');
//这里不采用自编id,而是采用美团统一id,这样即使产品更改自编id或者更改产品名称也可以第一时间识别出来
var tableHTML = "<table id='customers' contenteditable='true'><tr><th>马蜂窝ID</th><th>产品名称</th><th>出发地</th><th>品类</th><th>价格</th><th>销量</th><th>店铺名称</th></tr>";
var tmp;
$.each(items,(index,item) =>{
// console.log(item);
tableHTML += `<tr>
<td>${item.href.match(/\d{4,10}/)[0]}</td>
<td>${$(item).find('h3').text()}</td>
<td>${$(item).find('span strong').first().text()}</td>
<td>${$(item).find('span span').text()}</td>
<td>${$(item).find('span.price>strong').text()}</td>
<td>${$(item).find('.info p:first-child').text().length ? $(item).find('p').text().match(/\d{1,7}/) : 0}</td>
<td>${$(item).find('span.t').text().replace(/: /g,'')}</td>
</tr>`;
});

tableHTML += "<table>";
$("div.list-wrap").html(tableHTML);
}

function tableMode(){
// 表格在版块内,可滚动,内容可编辑
$('div.list-wrap').css({"overflow-x":"scroll"});
// 克隆翻页组件,上移,
$('#list_pagination').insertBefore($("div.sort-bar"));
//添加转换表格按钮
$("div.sort-bar>ul").append(`<li id="makeTable" class="sort-item"><a data-sort="sold_num">转成表格</a></li>`);
$("#makeTable").on("click",makeTable);
}

GM_addStyle(`
#customers{overflow:auto;white-space:nowrap}
#customers{font-family:"Trebuchet MS",Arial,Helvetica,sans-serif;width:100%;border-collapse:collapse;}
#customers td,#customers th{font-size:1em;border:1px solid #98bf21;padding:3px 7px 2px 7px;}
#customers th{text-align:left;padding-top:5px;padding-bottom:4px;background-color:#A7C942;color:#ffffff;}
#customers tr.alt td{color:#000000;background-color:#EAF2D3;}
`);
GM_registerMenuCommand('开启表格模式',tableMode,' ');

})();
9 changes: 9 additions & 0 deletions mafengwo/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 马蜂窝系列脚本

## mfwTripMall

##### 适用于旅行商城,把列表页面的数据项目整理为表格,用于辅助收集数据,便于分析

- 效果,把下面翻页列表往上面挪,方便快速翻页。
- 添加一个 `转成表格` 按钮,点击 `转成表格` 之后,在原来的列表项地方生成表格。
- 为了便于使用 `Ctrl + C` 复制数据,把表格数据 设置为“可编辑”,只需点击一下表格,然后 `Ctrl + A`,在 `Ctrl + C` 即可复制数据

0 comments on commit f76f78a

Please sign in to comment.