Created
March 22, 2017 03:25
-
-
Save takecian/11562c0d4c477a8adfa5199e45cf88b1 to your computer and use it in GitHub Desktop.
html tag を除去する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// WebUtility.swift | |
// npbsns | |
// | |
// Created by FUJIKI TAKESHI on 2016/02/05. | |
// Copyright © 2016年 Takeshi Fujiki. All rights reserved. | |
// | |
import UIKit | |
import WebKit | |
class WebUtility: NSObject { | |
class func createConfiguration() -> WKWebViewConfiguration { | |
let controller = WKUserContentController() | |
let ids = ["footerInner", "iconAd", "ad", "js-navBtn", "js-appBnr", "footer"] | |
for id in ids { | |
controller.addUserScript(WKUserScript(source: "document.getElementById('\(id)').innerHTML = '';", injectionTime: .atDocumentEnd, forMainFrameOnly: true)) | |
} | |
let classNames = ["plugin-ad", "plugin-blogroll", "blog_ad2", "footer-ranking", "footer-nav", "google-user-ad", "article_mid_lower_ad", "article_low_ad", "relatedService", "blog-footer-inner", "rsslink", "plugin-popular_articles-new", "plugin-free_area", "plugin-follow_buttons", "mod-outer-btn", "bh-b", "aboutPTV", "faqLink", "movieList", "menu-button-right", "searchTrigger"] | |
for className in classNames { | |
controller.addUserScript(WKUserScript(source: "(function (){ var elements = document.getElementsByClassName(\"\(className)\"); for (var i=0;i<elements.length;i++) { elements[i].style.display = \"none\"; } })();", injectionTime: .atDocumentEnd, forMainFrameOnly: true)) | |
} | |
let configuration = WKWebViewConfiguration() | |
configuration.userContentController = controller | |
return configuration | |
} | |
} | |
let configuration = WebUtility.createConfiguration() | |
webView = WKWebView(frame: view.bounds, configuration: configuration) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment